<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge" >
  <link rel="dns-prefetch" href="https://wgy1993.gitee.io">
  <title>MongoDB(二) | Wgy的博客</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="1.    副本集-Replica Sets1.1    简介MongoDB中的副本集（Replica Set）是一组维护相同数据集的mongod服务。 副本集可提供冗余和高可用性，是所有生产部署的基础。 也可以说，副本集类似于有自动故障恢复功能的主从集群。通俗的讲就是用多台机器进行同一数据的异步同步，从而使多台机器拥有同一数据的多个副本，并且当主库当掉时在不需要用户干预的情况下自动切换其他备份服">
<meta property="og:type" content="article">
<meta property="og:title" content="MongoDB(二)">
<meta property="og:url" content="https://wgy1993.gitee.io/archives/afe7047c.html">
<meta property="og:site_name" content="Wgy的博客">
<meta property="og:description" content="1.    副本集-Replica Sets1.1    简介MongoDB中的副本集（Replica Set）是一组维护相同数据集的mongod服务。 副本集可提供冗余和高可用性，是所有生产部署的基础。 也可以说，副本集类似于有自动故障恢复功能的主从集群。通俗的讲就是用多台机器进行同一数据的异步同步，从而使多台机器拥有同一数据的多个副本，并且当主库当掉时在不需要用户干预的情况下自动切换其他备份服">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200918164831238.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200918164912986.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200918164931592.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200918165004924.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/202009181650221.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200918165044703.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200918165105108.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/2020091816513874.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/2020091816515942.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200918165217814.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200918165235785.png">
<meta property="article:published_time" content="2020-09-18T08:54:22.000Z">
<meta property="article:modified_time" content="2021-04-04T15:02:57.390Z">
<meta property="article:author" content="Wgy">
<meta property="article:tag" content="NoSQL存储">
<meta property="article:tag" content="MongoDB">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/20200918164831238.png">
  
    <link rel="alternative" href="/atom.xml" title="Wgy的博客" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.jpg">
  
  <link rel="stylesheet" type="text/css" href="/./main.ee3baa.css">
  <!-- 旋转头像效果-->
    
  	<link rel="stylesheet" type="text/css" href="/./avatarrotation.css">
    
  <!-- 添加完成 -->
  <style type="text/css">
  
    #container.show {
      background: linear-gradient(200deg,#a0cfe4,#e8c37e);
    }
  </style>
  

  

<meta name="generator" content="Hexo 4.2.1"></head>

<body>
  <div id="container" q-class="show:isCtnShow">
    <canvas id="anm-canvas" class="anm-canvas"></canvas>
    <div class="left-col" q-class="show:isShow">
      
<div class="overlay" style="background: #4d4d4d"></div>
<div class="intrude-less">
	<header id="header" class="inner">
		<a href="/" class="profilepic">
			<img src="https://ae01.alicdn.com/kf/H0d10f38496b04070961ba4114c0f500es.jpg" class="js-avatar">
		</a>
		<hgroup>
		  <h1 class="header-author"><a href="/">Wgy</a></h1>
		</hgroup>
		
		<p class="header-subtitle">路漫漫其修远兮，吾将上下而求索。</p>
		

		<nav class="header-menu">
			<ul>
			
				<li><a href="/">主页</a></li>
	        
				<li><a href="/archives">归档</a></li>
	        
				<li><a href="/categories">分类</a></li>
	        
			</ul>
		</nav>
		<nav class="header-smart-menu">
    		
    			
    			<a q-on="click: openSlider(e, 'innerArchive')" href="javascript:void(0)">文章搜索</a>
    			
            
    			
    			<a q-on="click: openSlider(e, 'friends')" href="javascript:void(0)">友情链接</a>
    			
            
    			
    			<a q-on="click: openSlider(e, 'aboutme')" href="javascript:void(0)">关于我</a>
    			
            
		</nav>
		<nav class="header-nav">
			<div class="social">
				
					<a class="github" target="_blank" href="https://github.com/wgy1993" title="github"><i class="icon-github"></i></a>
		        
					<a class="mail" target="_blank" href="mailto:18727691214@163.com" title="mail"><i class="icon-mail"></i></a>
		        
					<a class="rss" target="_blank" href="/atom.xml" title="rss"><i class="icon-rss"></i></a>
		        
			</div>
		</nav>
	</header>		
</div>

    </div>
    <div class="mid-col" q-class="show:isShow,hide:isShow|isFalse">
      
<nav id="mobile-nav">
  	<div class="overlay js-overlay" style="background: #4d4d4d"></div>
	<div class="btnctn js-mobile-btnctn">
  		<div class="slider-trigger list" q-on="click: openSlider(e)"><i class="icon icon-sort"></i></div>
	</div>
	<div class="intrude-less">
		<header id="header" class="inner">
			<div class="profilepic">
				<img src="https://ae01.alicdn.com/kf/H0d10f38496b04070961ba4114c0f500es.jpg" class="js-avatar">
			</div>
			<hgroup>
			  <h1 class="header-author js-header-author">Wgy</h1>
			</hgroup>
			
			<p class="header-subtitle"><i class="icon icon-quo-left"></i>路漫漫其修远兮，吾将上下而求索。<i class="icon icon-quo-right"></i></p>
			
			
			
				
			
				
			
				
			
			
			
			<nav class="header-nav">
				<div class="social">
					
						<a class="github" target="_blank" href="https://github.com/wgy1993" title="github"><i class="icon-github"></i></a>
			        
						<a class="mail" target="_blank" href="mailto:18727691214@163.com" title="mail"><i class="icon-mail"></i></a>
			        
						<a class="rss" target="_blank" href="/atom.xml" title="rss"><i class="icon-rss"></i></a>
			        
				</div>
			</nav>

			<nav class="header-menu js-header-menu">
				<ul style="width: 70%">
				
				
					<li style="width: 33.333333333333336%"><a href="/">主页</a></li>
		        
					<li style="width: 33.333333333333336%"><a href="/archives">归档</a></li>
		        
					<li style="width: 33.333333333333336%"><a href="/categories">分类</a></li>
		        
				</ul>
			</nav>
		</header>				
	</div>
	<div class="mobile-mask" style="display:none" q-show="isShow"></div>
</nav>

      <div id="wrapper" class="body-wrap">
        <div class="menu-l">
          <div class="canvas-wrap">
            <canvas data-colors="#eaeaea" data-sectionHeight="100" data-contentId="js-content" id="myCanvas1" class="anm-canvas"></canvas>
          </div>
          <div id="js-content" class="content-ll">
            <article id="post-MongoDB-二" class="article article-type-post " itemscope itemprop="blogPost">
  <div class="article-inner">
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      MongoDB(二)
    </h1>
  

        
        <a href="/archives/afe7047c.html" class="archive-article-date">
  	<time datetime="2020-09-18T08:54:22.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2020-09-18</time>
</a>
        
      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="1-副本集-Replica-Sets"><a href="#1-副本集-Replica-Sets" class="headerlink" title="1.    副本集-Replica Sets"></a>1.    副本集-Replica Sets</h1><h2 id="1-1-简介"><a href="#1-1-简介" class="headerlink" title="1.1    简介"></a>1.1    简介</h2><p>MongoDB中的副本集（Replica Set）是一组维护相同数据集的mongod服务。 副本集可提供冗余和高可用性，是所有生产部署的基础。</p>
<p>也可以说，副本集类似于有自动故障恢复功能的主从集群。通俗的讲就是用多台机器进行同一数据的异步同步，从而使多台机器拥有同一数据的多个副本，并且当主库当掉时在不需要用户干预的情况下自动切换其他备份服务器做主库。而且还可以利用副本服务器做只读服务器，实现读写分离，提高负载。</p>
<a id="more"></a>

<p>（1）冗余和数据可用性</p>
<p>复制提供冗余并提高数据可用性。 通过在不同数据库服务器上提供多个数据副本，复制可提供一定级别的容错功能，以防止丢失单个数据库服务器。</p>
<p>在某些情况下，复制可以提供增加的读取性能，因为客户端可以将读取操作发送到不同的服务上， 在不同数据中心维护数据副本可以增加分布式应用程序的数据位置和可用性。 您还可以为专用目的维护其他副本，例如灾难恢复，报告或备份。</p>
<p>（2）MongoDB中的复制</p>
<p>副本集是一组维护相同数据集的mongod实例。 副本集包含多个数据承载节点和可选的一个仲裁节点。在承载数据的节点中，一个且仅一个成员被视为主节点，而其他节点被视为次要（从）节点。</p>
<p>主节点接收所有写操作。 副本集只能有一个主要能够确认具有{w：“most”}写入关注的写入; 虽然在某些情况下，另一个mongod实例可能暂时认为自己也是主要的。主要记录其操作日志中的数据集的所有更改，即oplog。</p>
<p><img src="https://img-blog.csdnimg.cn/20200918164831238.png" alt="image-20200918092648938"></p>
<p>辅助(副本)节点复制主节点的oplog并将操作应用于其数据集，以使辅助节点的数据集反映主节点的数据集。 如果主要人员不在，则符合条件的中学将举行选举以选出新的主要人员。</p>
<p>（3）主从复制和副本集区别</p>
<p>主从集群和副本集最大的区别就是副本集没有固定的“主节点”；整个集群会选出一个“主节点”，当其挂掉后，又在剩下的从节点中选中其他节点为“主节点”，副本集总有一个活跃点(主、primary)和一个或多个备份节点(从、secondary)。</p>
<h2 id="1-2-副本集的三个角色"><a href="#1-2-副本集的三个角色" class="headerlink" title="1.2    副本集的三个角色"></a>1.2    副本集的三个角色</h2><p>副本集有两种类型三种角色</p>
<p>两种类型：</p>
<ul>
<li>主节点（ Primary）类型：数据操作的主要连接点，可读写。</li>
<li>次要（辅助、从）节点（ Secondaries）类型：数据冗余备份节点，可以读或选举。</li>
</ul>
<p>三种角色：</p>
<ul>
<li>主要成员（Primary）：主要接收所有写操作。就是主节点。</li>
<li>副本成员（Replicate）：从主节点通过复制操作以维护相同的数据集，即备份数据，不可写操作，但可以读操作（但需要配置）。是默认的一种从节点类型。</li>
<li>仲裁者（ Arbiter）：不保留任何数据的副本，只具有投票选举作用。当然也可以将仲裁服务器维护为副本集的一部分，即副本成员同时也可以是仲裁者。也是一种从节点类型。</li>
</ul>
<p><img src="https://img-blog.csdnimg.cn/20200918164912986.png" alt="image-20200918092959669"></p>
<p>关于仲裁者的额外说明：</p>
<p>您可以将额外的mongod实例添加到副本集作为仲裁者。 仲裁者不维护数据集。 仲裁者的目的是通过响应其他副本集成员的心跳和选举请求来维护副本集中的仲裁。 因为它们不存储数据集，所以仲裁器可以是提供副本集仲裁功能的好方法，其资源成本比具有数据集的全功能副本集成员更便宜。</p>
<p>如果您的副本集具有偶数个成员，请添加仲裁者以获得主要选举中的“大多数”投票。 仲裁者不需要专用硬件。</p>
<p>仲裁者将永远是仲裁者，而主要人员可能会退出并成为次要人员，而次要人员可能成为选举期间的主要人员。</p>
<p>如果你的副本+主节点的个数是偶数，建议加一个仲裁者，形成奇数，容易满足大多数的投票。</p>
<p>如果你的副本+主节点的个数是奇数，可以不加仲裁者。</p>
<h2 id="1-3-副本集架构目标"><a href="#1-3-副本集架构目标" class="headerlink" title="1.3    副本集架构目标"></a>1.3    副本集架构目标</h2><p>一主一副本一仲裁</p>
<p><img src="https://img-blog.csdnimg.cn/20200918164931592.png" alt="image-20200918093150930"></p>
<h2 id="1-4-副本集的创建"><a href="#1-4-副本集的创建" class="headerlink" title="1.4    副本集的创建"></a>1.4    副本集的创建</h2><h3 id="1-4-1-第一步：创建主节点"><a href="#1-4-1-第一步：创建主节点" class="headerlink" title="1.4.1    第一步：创建主节点"></a>1.4.1    第一步：创建主节点</h3><p>建立存放数据和日志的目录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#-----------myrs</span></span><br><span class="line"><span class="comment">#主节点</span></span><br><span class="line">mkdir -p /mongodb/replica_sets/myrs_27017/<span class="built_in">log</span> \ &amp;</span><br><span class="line">mkdir -p /mongodb/replica_sets/myrs_27017/data/db</span><br></pre></td></tr></table></figure>

<p>新建或修改配置文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /mongodb/replica_sets/myrs_27017/mongod.conf</span><br></pre></td></tr></table></figure>

<p>myrs_27017 ：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">systemLog:</span></span><br><span class="line">    <span class="comment">#MongoDB发送所有日志输出的目标指定为文件</span></span><br><span class="line">    <span class="attr">destination:</span> <span class="string">file</span></span><br><span class="line">    <span class="comment">#mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径</span></span><br><span class="line">    <span class="attr">path:</span> <span class="string">"/mongodb/replica_sets/myrs_27017/log/mongod.log"</span></span><br><span class="line">    <span class="comment">#当mongos或mongod实例重新启动时，mongos或mongod会将新条目附加到现有日志文件的末尾。</span></span><br><span class="line">    <span class="attr">logAppend:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">storage:</span></span><br><span class="line">    <span class="comment">#mongod实例存储其数据的目录。storage.dbPath设置仅适用于mongod。</span></span><br><span class="line">    <span class="attr">dbPath:</span> <span class="string">"/mongodb/replica_sets/myrs_27017/data/db"</span></span><br><span class="line">    <span class="attr">journal:</span></span><br><span class="line">        <span class="comment">#启用或禁用持久性日志以确保数据文件保持有效和可恢复。</span></span><br><span class="line">        <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">processManagement:</span></span><br><span class="line">    <span class="comment">#启用在后台运行mongos或mongod进程的守护进程模式。</span></span><br><span class="line">    <span class="attr">fork:</span> <span class="literal">true</span></span><br><span class="line">    <span class="comment">#指定用于保存mongos或mongod进程的进程ID的文件位置，其中mongos或mongod将写入其PID</span></span><br><span class="line">    <span class="attr">pidFilePath:</span> <span class="string">"/mongodb/replica_sets/myrs_27017/log/mongod.pid"</span></span><br><span class="line"><span class="attr">net:</span></span><br><span class="line">    <span class="comment">#服务实例绑定所有IP，有副作用，副本集初始化的时候，节点名字会自动设置为本地域名，而不是ip</span></span><br><span class="line">    <span class="comment">#bindIpAll: true</span></span><br><span class="line">    <span class="comment">#服务实例绑定的IP</span></span><br><span class="line">    <span class="attr">bindIp:</span> <span class="string">localhost,192.168.0.2</span></span><br><span class="line">    <span class="comment">#bindIp</span></span><br><span class="line">    <span class="comment">#绑定的端口</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">27017</span></span><br><span class="line"><span class="attr">replication:</span></span><br><span class="line">    <span class="comment">#副本集的名称</span></span><br><span class="line">    <span class="attr">replSetName:</span> <span class="string">myrs</span></span><br></pre></td></tr></table></figure>

<p>启动节点服务：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost replica_sets]<span class="comment"># /usr/local/mongodb/bin/mongod -f /mongodb/replica_sets/myrs_27017/mongod.conf</span></span><br><span class="line">about to fork child process, waiting until server is ready <span class="keyword">for</span> connections.</span><br><span class="line">forked process: 54257</span><br><span class="line">child process started successfully, parent exiting</span><br></pre></td></tr></table></figure>

<h3 id="1-4-2-第二步：创建副本节点"><a href="#1-4-2-第二步：创建副本节点" class="headerlink" title="1.4.2    第二步：创建副本节点"></a>1.4.2    第二步：创建副本节点</h3><p>建立存放数据和日志的目录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#-----------myrs</span></span><br><span class="line"><span class="comment">#副本节点</span></span><br><span class="line">mkdir -p /mongodb/replica_sets/myrs_27018/<span class="built_in">log</span> \ &amp;</span><br><span class="line">mkdir -p /mongodb/replica_sets/myrs_27018/data/db</span><br></pre></td></tr></table></figure>

<p>新建或修改配置文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /mongodb/replica_sets/myrs_27018/mongod.conf</span><br></pre></td></tr></table></figure>

<p>myrs_27018 ：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">systemLog:</span></span><br><span class="line">    <span class="comment">#MongoDB发送所有日志输出的目标指定为文件</span></span><br><span class="line">    <span class="attr">destination:</span> <span class="string">file</span></span><br><span class="line">    <span class="comment">#mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径</span></span><br><span class="line">    <span class="attr">path:</span> <span class="string">"/mongodb/replica_sets/myrs_27018/log/mongod.log"</span></span><br><span class="line">    <span class="comment">#当mongos或mongod实例重新启动时，mongos或mongod会将新条目附加到现有日志文件的末尾。</span></span><br><span class="line">    <span class="attr">logAppend:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">storage:</span></span><br><span class="line">    <span class="comment">#mongod实例存储其数据的目录。storage.dbPath设置仅适用于mongod。</span></span><br><span class="line">    <span class="attr">dbPath:</span> <span class="string">"/mongodb/replica_sets/myrs_27018/data/db"</span></span><br><span class="line">    <span class="attr">journal:</span></span><br><span class="line">        <span class="comment">#启用或禁用持久性日志以确保数据文件保持有效和可恢复。</span></span><br><span class="line">        <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">processManagement:</span></span><br><span class="line">    <span class="comment">#启用在后台运行mongos或mongod进程的守护进程模式。</span></span><br><span class="line">    <span class="attr">fork:</span> <span class="literal">true</span></span><br><span class="line">    <span class="comment">#指定用于保存mongos或mongod进程的进程ID的文件位置，其中mongos或mongod将写入其PID</span></span><br><span class="line">    <span class="attr">pidFilePath:</span> <span class="string">"/mongodb/replica_sets/myrs_27018/log/mongod.pid"</span></span><br><span class="line"><span class="attr">net:</span></span><br><span class="line">    <span class="comment">#服务实例绑定所有IP，有副作用，副本集初始化的时候，节点名字会自动设置为本地域名，而不是ip</span></span><br><span class="line">    <span class="comment">#bindIpAll: true</span></span><br><span class="line">    <span class="comment">#服务实例绑定的IP</span></span><br><span class="line">    <span class="attr">bindIp:</span> <span class="string">localhost,192.168.0.2</span></span><br><span class="line">    <span class="comment">#bindIp</span></span><br><span class="line">    <span class="comment">#绑定的端口</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">27018</span></span><br><span class="line"><span class="attr">replication:</span></span><br><span class="line">    <span class="comment">#副本集的名称</span></span><br><span class="line">    <span class="attr">replSetName:</span> <span class="string">myrs</span></span><br></pre></td></tr></table></figure>

<p>启动节点服务：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost replica_sets]<span class="comment"># /usr/local/mongodb/bin/mongod -f /mongodb/replica_sets/myrs_27018/mongod.conf</span></span><br><span class="line">about to fork child process, waiting until server is ready <span class="keyword">for</span> connections.</span><br><span class="line">forked process: 54361</span><br><span class="line">child process started successfully, parent exiting</span><br></pre></td></tr></table></figure>

<h3 id="1-4-3-第三步：创建仲裁节点"><a href="#1-4-3-第三步：创建仲裁节点" class="headerlink" title="1.4.3    第三步：创建仲裁节点"></a>1.4.3    第三步：创建仲裁节点</h3><p>建立存放数据和日志的目录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#-----------myrs</span></span><br><span class="line"><span class="comment">#仲裁节点</span></span><br><span class="line">mkdir -p /mongodb/replica_sets/myrs_27019/<span class="built_in">log</span> \ &amp;</span><br><span class="line">mkdir -p /mongodb/replica_sets/myrs_27019/data/db</span><br></pre></td></tr></table></figure>

<p>新建或修改配置文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /mongodb/replica_sets/myrs_27019/mongod.conf</span><br></pre></td></tr></table></figure>

<p>myrs_27019 ：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">systemLog:</span></span><br><span class="line">    <span class="comment">#MongoDB发送所有日志输出的目标指定为文件</span></span><br><span class="line">    <span class="attr">destination:</span> <span class="string">file</span></span><br><span class="line">    <span class="comment">#mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径</span></span><br><span class="line">    <span class="attr">path:</span> <span class="string">"/mongodb/replica_sets/myrs_27019/log/mongod.log"</span></span><br><span class="line">    <span class="comment">#当mongos或mongod实例重新启动时，mongos或mongod会将新条目附加到现有日志文件的末尾。</span></span><br><span class="line">    <span class="attr">logAppend:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">storage:</span></span><br><span class="line">    <span class="comment">#mongod实例存储其数据的目录。storage.dbPath设置仅适用于mongod。</span></span><br><span class="line">    <span class="attr">dbPath:</span> <span class="string">"/mongodb/replica_sets/myrs_27019/data/db"</span></span><br><span class="line">    <span class="attr">journal:</span></span><br><span class="line">        <span class="comment">#启用或禁用持久性日志以确保数据文件保持有效和可恢复。</span></span><br><span class="line">        <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">processManagement:</span></span><br><span class="line">    <span class="comment">#启用在后台运行mongos或mongod进程的守护进程模式。</span></span><br><span class="line">    <span class="attr">fork:</span> <span class="literal">true</span></span><br><span class="line">    <span class="comment">#指定用于保存mongos或mongod进程的进程ID的文件位置，其中mongos或mongod将写入其PID</span></span><br><span class="line">    <span class="attr">pidFilePath:</span> <span class="string">"/mongodb/replica_sets/myrs_27019/log/mongod.pid"</span></span><br><span class="line"><span class="attr">net:</span></span><br><span class="line">    <span class="comment">#服务实例绑定所有IP，有副作用，副本集初始化的时候，节点名字会自动设置为本地域名，而不是ip</span></span><br><span class="line">    <span class="comment">#bindIpAll: true</span></span><br><span class="line">    <span class="comment">#服务实例绑定的IP</span></span><br><span class="line">    <span class="attr">bindIp:</span> <span class="string">localhost,192.168.0.2</span></span><br><span class="line">    <span class="comment">#bindIp</span></span><br><span class="line">    <span class="comment">#绑定的端口</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">27019</span></span><br><span class="line"><span class="attr">replication:</span></span><br><span class="line">    <span class="comment">#副本集的名称</span></span><br><span class="line">    <span class="attr">replSetName:</span> <span class="string">myrs</span></span><br></pre></td></tr></table></figure>

<p>启动节点服务：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost replica_sets]<span class="comment"># /usr/local/mongodb/bin/mongod -f /mongodb/replica_sets/myrs_27019/mongod.conf</span></span><br><span class="line">about to fork child process, waiting until server is ready <span class="keyword">for</span> connections.</span><br><span class="line">forked process: 54410</span><br><span class="line">child process started successfully, parent exiting</span><br></pre></td></tr></table></figure>

<h3 id="1-4-4-第四步：初始化配置副本集和主节点"><a href="#1-4-4-第四步：初始化配置副本集和主节点" class="headerlink" title="1.4.4    第四步：初始化配置副本集和主节点"></a>1.4.4    第四步：初始化配置副本集和主节点</h3><p>使用客户端命令连接任意一个节点，但这里尽量要连接主节点(27017节点)：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongo --host=180.76.159.126 --port=27017</span><br></pre></td></tr></table></figure>

<p>结果，连接上之后，很多命令无法使用，，比如 show dbs 等，必须初始化副本集才行</p>
<p>准备初始化新的副本集：</p>
<p>语法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.initiate(configuration)</span><br></pre></td></tr></table></figure>

<p>【示例】</p>
<p>使用默认的配置来初始化副本集：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.initiate()</span><br></pre></td></tr></table></figure>

<p>执行结果：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">&gt; rs.initiate()</span><br><span class="line">&#123;</span><br><span class="line">    &quot;info2&quot; : &quot;no configuration specified. Using a default configuration for the set&quot;,</span><br><span class="line">    &quot;me&quot; : &quot;180.76.159.126:27017&quot;,</span><br><span class="line">    &quot;ok&quot; : 1,</span><br><span class="line">    &quot;operationTime&quot; : Timestamp(1565760476, 1),</span><br><span class="line">    &quot;$clusterTime&quot; : &#123;</span><br><span class="line">        &quot;clusterTime&quot; : Timestamp(1565760476, 1),</span><br><span class="line">        &quot;signature&quot; : &#123;</span><br><span class="line">            &quot;hash&quot; : BinData(0,&quot;AAAAAAAAAAAAAAAAAAAAAAAAAAA&#x3D;&quot;),</span><br><span class="line">            &quot;keyId&quot; : NumberLong(0)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">myrs:SECONDARY&gt;</span><br><span class="line">myrs:PRIMARY&gt;</span><br></pre></td></tr></table></figure>

<p>提示：</p>
<ul>
<li>“ok”的值为1，说明创建成功。</li>
<li>命令行提示符发生变化，变成了一个从节点角色，此时默认不能读写。稍等片刻，回车，变成主节点。</li>
</ul>
<h3 id="1-4-5-第五步：查看副本集的配置内容"><a href="#1-4-5-第五步：查看副本集的配置内容" class="headerlink" title="1.4.5    第五步：查看副本集的配置内容"></a>1.4.5    第五步：查看副本集的配置内容</h3><p>返回包含当前副本集配置的文档。</p>
<p>语法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.conf(configuration)</span><br></pre></td></tr></table></figure>

<p>提示：</p>
<p><code>rs.config()</code> 是该方法的别名。</p>
<p>configuration：可选，如果没有配置，则使用默认主节点配置。</p>
<p>【示例】</p>
<p>在27017上执行副本集中当前节点的默认节点配置</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">myrs:PRIMARY&gt; rs.conf()</span><br><span class="line">&#123;</span><br><span class="line">    &quot;_id&quot; : &quot;myrs&quot;,</span><br><span class="line">    &quot;version&quot; : 1,</span><br><span class="line">    &quot;protocolVersion&quot; : NumberLong(1),</span><br><span class="line">    &quot;writeConcernMajorityJournalDefault&quot; : true,</span><br><span class="line">    &quot;members&quot; : [</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;_id&quot; : 0,</span><br><span class="line">            &quot;host&quot; : &quot;180.76.159.126:27017&quot;,</span><br><span class="line">            &quot;arbiterOnly&quot; : false,</span><br><span class="line">            &quot;buildIndexes&quot; : true,</span><br><span class="line">            &quot;hidden&quot; : false,</span><br><span class="line">            &quot;priority&quot; : 1,</span><br><span class="line">            &quot;tags&quot; : &#123;</span><br><span class="line"></span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;slaveDelay&quot; : NumberLong(0),</span><br><span class="line">            &quot;votes&quot; : 1</span><br><span class="line">        &#125;</span><br><span class="line">    ],</span><br><span class="line">    &quot;settings&quot; : &#123;</span><br><span class="line">        &quot;chainingAllowed&quot; : true,</span><br><span class="line">        &quot;heartbeatIntervalMillis&quot; : 2000,</span><br><span class="line">        &quot;heartbeatTimeoutSecs&quot; : 10,</span><br><span class="line">        &quot;electionTimeoutMillis&quot; : 10000,</span><br><span class="line">        &quot;catchUpTimeoutMillis&quot; : -1,</span><br><span class="line">        &quot;catchUpTakeoverDelayMillis&quot; : 30000,</span><br><span class="line">        &quot;getLastErrorModes&quot; : &#123;</span><br><span class="line">        </span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;getLastErrorDefaults&quot; : &#123;</span><br><span class="line">            &quot;w&quot; : 1,</span><br><span class="line">            &quot;wtimeout&quot; : 0</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;replicaSetId&quot; : ObjectId(&quot;5d539bdcd6a308e600d126bb&quot;)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>说明：</p>
<ul>
<li><code>&quot;_id&quot; : &quot;myrs&quot;</code> ：副本集的配置数据存储的主键值，默认就是副本集的名字</li>
<li><code>&quot;members&quot;</code> ：副本集成员数组，此时只有一个： “host” : “180.76.159.126:27017” ，该成员不是仲裁节点：”arbiterOnly” : false ，优先级（权重值）： “priority” : 1,</li>
<li><code>&quot;settings&quot;</code> ：副本集的参数配置。</li>
</ul>
<p>提示：副本集配置的查看命令，本质是查询的是 system.replset 的表中的数据：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">myrs:PRIMARY&gt; use local</span><br><span class="line">switched to db local</span><br><span class="line">myrs:PRIMARY&gt; show collections</span><br><span class="line">oplog.rs</span><br><span class="line">replset.election</span><br><span class="line">replset.minvalid</span><br><span class="line">replset.oplogTruncateAfterPoint</span><br><span class="line">startup_log</span><br><span class="line">system.replset</span><br><span class="line">system.rollback.id</span><br><span class="line">myrs:PRIMARY&gt; db.system.replset.find()</span><br><span class="line">&#123; &quot;_id&quot; : &quot;myrs&quot;, &quot;version&quot; : 1, &quot;protocolVersion&quot; : NumberLong(1),</span><br><span class="line">&quot;writeConcernMajorityJournalDefault&quot; : true, &quot;members&quot; : [ &#123; &quot;_id&quot; : 0, &quot;host&quot; :</span><br><span class="line">&quot;180.76.159.126:27017&quot;, &quot;arbiterOnly&quot; : false, &quot;buildIndexes&quot; : true, &quot;hidden&quot; :</span><br><span class="line">false, &quot;priority&quot; : 1, &quot;tags&quot; : &#123; &#125;, &quot;slaveDelay&quot; : NumberLong(0), &quot;votes&quot; : 1</span><br><span class="line">&#125; ], &quot;settings&quot; : &#123; &quot;chainingAllowed&quot; : true, &quot;heartbeatIntervalMillis&quot; : 2000,</span><br><span class="line">&quot;heartbeatTimeoutSecs&quot; : 10, &quot;electionTimeoutMillis&quot; : 10000,</span><br><span class="line">&quot;catchUpTimeoutMillis&quot; : -1, &quot;catchUpTakeoverDelayMillis&quot; : 30000,</span><br><span class="line">&quot;getLastErrorModes&quot; : &#123; &#125;, &quot;getLastErrorDefaults&quot; : &#123; &quot;w&quot; : 1, &quot;wtimeout&quot; : 0</span><br><span class="line">&#125;, &quot;replicaSetId&quot; : ObjectId(&quot;5d539bdcd6a308e600d126bb&quot;) &#125; &#125;</span><br><span class="line">myrs:PRIMARY&gt;</span><br></pre></td></tr></table></figure>

<h3 id="1-4-6-第六步：查看副本集状态"><a href="#1-4-6-第六步：查看副本集状态" class="headerlink" title="1.4.6    第六步：查看副本集状态"></a>1.4.6    第六步：查看副本集状态</h3><p>检查副本集状态。</p>
<p>说明：</p>
<p>返回包含状态信息的文档。此输出使用从副本集的其他成员发送的心跳包中获得的数据反映副本集的当前状态。</p>
<p>语法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.status()</span><br></pre></td></tr></table></figure>

<p>【示例】</p>
<p>在27017上查看副本集状态：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line">myrs:PRIMARY&gt; rs.status()</span><br><span class="line">&#123;</span><br><span class="line">    &quot;set&quot; : &quot;myrs&quot;,</span><br><span class="line">    &quot;date&quot; : ISODate(&quot;2019-08-14T05:29:45.161Z&quot;),</span><br><span class="line">    &quot;myState&quot; : 1,</span><br><span class="line">    &quot;term&quot; : NumberLong(1),</span><br><span class="line">    &quot;syncingTo&quot; : &quot;&quot;,</span><br><span class="line">    &quot;syncSourceHost&quot; : &quot;&quot;,</span><br><span class="line">    &quot;syncSourceId&quot; : -1,</span><br><span class="line">    &quot;heartbeatIntervalMillis&quot; : NumberLong(2000),</span><br><span class="line">    &quot;optimes&quot; : &#123;</span><br><span class="line">        &quot;lastCommittedOpTime&quot; : &#123;</span><br><span class="line">            &quot;ts&quot; : Timestamp(1565760578, 1),</span><br><span class="line">            &quot;t&quot; : NumberLong(1)</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;readConcernMajorityOpTime&quot; : &#123;</span><br><span class="line">            &quot;ts&quot; : Timestamp(1565760578, 1),</span><br><span class="line">            &quot;t&quot; : NumberLong(1)</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;appliedOpTime&quot; : &#123;</span><br><span class="line">            &quot;ts&quot; : Timestamp(1565760578, 1),</span><br><span class="line">            &quot;t&quot; : NumberLong(1)</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;durableOpTime&quot; : &#123;</span><br><span class="line">            &quot;ts&quot; : Timestamp(1565760578, 1),</span><br><span class="line">            &quot;t&quot; : NumberLong(1)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    &quot;lastStableCheckpointTimestamp&quot; : Timestamp(1565760528, 1),</span><br><span class="line">    &quot;members&quot; : [</span><br><span class="line">        &#123;</span><br><span class="line">        &quot;_id&quot; : 0,</span><br><span class="line">        &quot;name&quot; : &quot;180.76.159.126:27017&quot;,</span><br><span class="line">        &quot;health&quot; : 1,</span><br><span class="line">        &quot;state&quot; : 1,</span><br><span class="line">        &quot;stateStr&quot; : &quot;PRIMARY&quot;,</span><br><span class="line">        &quot;uptime&quot; : 419,</span><br><span class="line">        &quot;optime&quot; : &#123;</span><br><span class="line">            &quot;ts&quot; : Timestamp(1565760578, 1),</span><br><span class="line">            &quot;t&quot; : NumberLong(1)</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;optimeDate&quot; : ISODate(&quot;2019-08-14T05:29:38Z&quot;),</span><br><span class="line">        &quot;syncingTo&quot; : &quot;&quot;,</span><br><span class="line">        &quot;syncSourceHost&quot; : &quot;&quot;,</span><br><span class="line">        &quot;syncSourceId&quot; : -1,</span><br><span class="line">        &quot;infoMessage&quot; : &quot;could not find member to sync from&quot;,</span><br><span class="line">        &quot;electionTime&quot; : Timestamp(1565760476, 2),</span><br><span class="line">        &quot;electionDate&quot; : ISODate(&quot;2019-08-14T05:27:56Z&quot;),</span><br><span class="line">        &quot;configVersion&quot; : 1,</span><br><span class="line">        &quot;self&quot; : true,</span><br><span class="line">        &quot;lastHeartbeatMessage&quot; : &quot;&quot;</span><br><span class="line">        &#125;</span><br><span class="line">    ],</span><br><span class="line">    &quot;ok&quot; : 1,</span><br><span class="line">    &quot;operationTime&quot; : Timestamp(1565760578, 1),</span><br><span class="line">    &quot;$clusterTime&quot; : &#123;</span><br><span class="line">        &quot;clusterTime&quot; : Timestamp(1565760578, 1),</span><br><span class="line">        &quot;signature&quot; : &#123;</span><br><span class="line">            &quot;hash&quot; : BinData(0,&quot;AAAAAAAAAAAAAAAAAAAAAAAAAAA&#x3D;&quot;),</span><br><span class="line">            &quot;keyId&quot; : NumberLong(0)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>说明：</p>
<ul>
<li><code>&quot;set&quot; : &quot;myrs&quot;</code> ：副本集的名字</li>
<li><code>&quot;myState&quot;</code> : 1：说明状态正常</li>
<li><code>&quot;members&quot;</code> ：副本集成员数组，此时只有一个： <code>&quot;name&quot; : &quot;180.76.159.126:27017&quot;</code> ，该成员的角色是 <code>&quot;stateStr&quot; : &quot;PRIMARY&quot;</code>, 该节点是健康的： <code>&quot;health&quot; : 1</code> 。</li>
</ul>
<h3 id="1-4-7-第七步：添加副本从节点"><a href="#1-4-7-第七步：添加副本从节点" class="headerlink" title="1.4.7    第七步：添加副本从节点"></a>1.4.7    第七步：添加副本从节点</h3><p>在主节点添加从节点，将其他成员加入到副本集</p>
<p>语法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.add(host, arbiterOnly)</span><br></pre></td></tr></table></figure>

<p>选项：</p>
<table>
<thead>
<tr>
<th>Parameter</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr>
<td>host</td>
<td>string or document</td>
<td>要添加到副本集的新成员。 指定为字符串或配置文档：1）如果是一个字符串，则需要指定新成员的主机名和可选的端口号；2）如果是一个文档，请指定在members数组中找到的副本集成员配置文档。 您必须在成员配置文档中指定主机字段。有关文档配置字段的说明，详见下方文档：“主机成员的配置文档”</td>
</tr>
<tr>
<td>arbiterOnly</td>
<td>boolean</td>
<td>可选的。 仅在 <host> 值为字符串时适用。 如果为true，则添加的主机是仲裁者。</td>
</tr>
</tbody></table>
<p>主机成员的配置文档：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    _id: &lt;int&gt;,</span><br><span class="line">    host: &lt;string&gt;,     &#x2F;&#x2F; required</span><br><span class="line">    arbiterOnly: &lt;boolean&gt;,</span><br><span class="line">    buildIndexes: &lt;boolean&gt;,</span><br><span class="line">    hidden: &lt;boolean&gt;,</span><br><span class="line">    priority: &lt;number&gt;,</span><br><span class="line">    tags: &lt;document&gt;,</span><br><span class="line">    slaveDelay: &lt;int&gt;,</span><br><span class="line">    votes: &lt;number&gt;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>【示例】</p>
<p>将27018的副本节点添加到副本集中：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">myrs:PRIMARY&gt; rs.add(&quot;180.76.159.126:27018&quot;)</span><br><span class="line">&#123;</span><br><span class="line">    &quot;ok&quot; : 1,</span><br><span class="line">    &quot;operationTime&quot; : Timestamp(1565761757, 1),</span><br><span class="line">    &quot;$clusterTime&quot; : &#123;</span><br><span class="line">        &quot;clusterTime&quot; : Timestamp(1565761757, 1),</span><br><span class="line">        &quot;signature&quot; : &#123;</span><br><span class="line">            &quot;hash&quot; : BinData(0,&quot;AAAAAAAAAAAAAAAAAAAAAAAAAAA&#x3D;&quot;),</span><br><span class="line">            &quot;keyId&quot; : NumberLong(0)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>说明：</p>
<ul>
<li>“ok” : 1 ：说明添加成功。</li>
</ul>
<p>查看副本集状态：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br></pre></td><td class="code"><pre><span class="line">myrs:PRIMARY&gt; rs.status()</span><br><span class="line">&#123;</span><br><span class="line">    &quot;set&quot; : &quot;myrs&quot;,</span><br><span class="line">    &quot;date&quot; : ISODate(&quot;2019-08-14T05:50:05.738Z&quot;),</span><br><span class="line">    &quot;myState&quot; : 1,</span><br><span class="line">    &quot;term&quot; : NumberLong(1),</span><br><span class="line">    &quot;syncingTo&quot; : &quot;&quot;,</span><br><span class="line">    &quot;syncSourceHost&quot; : &quot;&quot;,</span><br><span class="line">    &quot;syncSourceId&quot; : -1,</span><br><span class="line">    &quot;heartbeatIntervalMillis&quot; : NumberLong(2000),</span><br><span class="line">    &quot;optimes&quot; : &#123;</span><br><span class="line">        &quot;lastCommittedOpTime&quot; : &#123;</span><br><span class="line">            &quot;ts&quot; : Timestamp(1565761798, 1),</span><br><span class="line">            &quot;t&quot; : NumberLong(1)</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;readConcernMajorityOpTime&quot; : &#123;</span><br><span class="line">            &quot;ts&quot; : Timestamp(1565761798, 1),</span><br><span class="line">            &quot;t&quot; : NumberLong(1)</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;appliedOpTime&quot; : &#123;</span><br><span class="line">            &quot;ts&quot; : Timestamp(1565761798, 1),</span><br><span class="line">            &quot;t&quot; : NumberLong(1)</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;durableOpTime&quot; : &#123;</span><br><span class="line">            &quot;ts&quot; : Timestamp(1565761798, 1),</span><br><span class="line">            &quot;t&quot; : NumberLong(1)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    &quot;lastStableCheckpointTimestamp&quot; : Timestamp(1565761798, 1),</span><br><span class="line">    &quot;members&quot; : [</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;_id&quot; : 0,</span><br><span class="line">            &quot;name&quot; : &quot;180.76.159.126:27017&quot;,</span><br><span class="line">            &quot;health&quot; : 1,</span><br><span class="line">            &quot;state&quot; : 1,</span><br><span class="line">            &quot;stateStr&quot; : &quot;PRIMARY&quot;,</span><br><span class="line">            &quot;uptime&quot; : 1639,</span><br><span class="line">            &quot;optime&quot; : &#123;</span><br><span class="line">                &quot;ts&quot; : Timestamp(1565761798, 1),</span><br><span class="line">                &quot;t&quot; : NumberLong(1)</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;optimeDate&quot; : ISODate(&quot;2019-08-14T05:49:58Z&quot;),</span><br><span class="line">            &quot;syncingTo&quot; : &quot;&quot;,</span><br><span class="line">            &quot;syncSourceHost&quot; : &quot;&quot;,</span><br><span class="line">            &quot;syncSourceId&quot; : -1,</span><br><span class="line">            &quot;infoMessage&quot; : &quot;&quot;,</span><br><span class="line">            &quot;electionTime&quot; : Timestamp(1565760476, 2),</span><br><span class="line">            &quot;electionDate&quot; : ISODate(&quot;2019-08-14T05:27:56Z&quot;),</span><br><span class="line">            &quot;configVersion&quot; : 2,</span><br><span class="line">            &quot;self&quot; : true,</span><br><span class="line">            &quot;lastHeartbeatMessage&quot; : &quot;&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;_id&quot; : 1,</span><br><span class="line">            &quot;name&quot; : &quot;180.76.159.126:27018&quot;,</span><br><span class="line">            &quot;health&quot; : 1,</span><br><span class="line">            &quot;state&quot; : 2,</span><br><span class="line">            &quot;stateStr&quot; : &quot;SECONDARY&quot;,</span><br><span class="line">            &quot;uptime&quot; : 48,</span><br><span class="line">            &quot;optime&quot; : &#123;</span><br><span class="line">                &quot;ts&quot; : Timestamp(1565761798, 1),</span><br><span class="line">                &quot;t&quot; : NumberLong(1)</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;optimeDurable&quot; : &#123;</span><br><span class="line">                &quot;ts&quot; : Timestamp(1565761798, 1),</span><br><span class="line">                &quot;t&quot; : NumberLong(1)</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;optimeDate&quot; : ISODate(&quot;2019-08-14T05:49:58Z&quot;),</span><br><span class="line">            &quot;optimeDurableDate&quot; : ISODate(&quot;2019-08-14T05:49:58Z&quot;),</span><br><span class="line">            &quot;lastHeartbeat&quot; : ISODate(&quot;2019-08-14T05:50:05.294Z&quot;),</span><br><span class="line">            &quot;lastHeartbeatRecv&quot; : ISODate(&quot;2019-08-</span><br><span class="line">            14T05:50:05.476Z&quot;),</span><br><span class="line">            &quot;pingMs&quot; : NumberLong(0),</span><br><span class="line">            &quot;lastHeartbeatMessage&quot; : &quot;&quot;,</span><br><span class="line">            &quot;syncingTo&quot; : &quot;180.76.159.126:27017&quot;,</span><br><span class="line">            &quot;syncSourceHost&quot; : &quot;180.76.159.126:27017&quot;,</span><br><span class="line">            &quot;syncSourceId&quot; : 0,</span><br><span class="line">            &quot;infoMessage&quot; : &quot;&quot;,</span><br><span class="line">            &quot;configVersion&quot; : 2</span><br><span class="line">        &#125;</span><br><span class="line">    ],</span><br><span class="line">    &quot;ok&quot; : 1,</span><br><span class="line">    &quot;operationTime&quot; : Timestamp(1565761798, 1),</span><br><span class="line">    &quot;$clusterTime&quot; : &#123;</span><br><span class="line">        &quot;clusterTime&quot; : Timestamp(1565761798, 1),</span><br><span class="line">        &quot;signature&quot; : &#123;</span><br><span class="line">            &quot;hash&quot; : BinData(0,&quot;AAAAAAAAAAAAAAAAAAAAAAAAAAA&#x3D;&quot;),</span><br><span class="line">            &quot;keyId&quot; : NumberLong(0)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>说明：</p>
<ul>
<li><code>&quot;name&quot; : &quot;180.76.159.126:27018&quot;</code> 是第二个节点的名字，其角色是 <code>&quot;stateStr&quot; : &quot;SECONDARY&quot;</code></li>
</ul>
<h3 id="1-4-8-第八步：添加仲裁从节点"><a href="#1-4-8-第八步：添加仲裁从节点" class="headerlink" title="1.4.8    第八步：添加仲裁从节点"></a>1.4.8    第八步：添加仲裁从节点</h3><p>添加一个仲裁节点到副本集</p>
<p>语法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.addArb(host)</span><br></pre></td></tr></table></figure>

<p>将27019的仲裁节点添加到副本集中：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">myrs:PRIMARY&gt; rs.addArb(&quot;180.76.159.126:27019&quot;)</span><br><span class="line">&#123;</span><br><span class="line">    &quot;ok&quot; : 1,</span><br><span class="line">    &quot;operationTime&quot; : Timestamp(1565761959, 1),</span><br><span class="line">    &quot;$clusterTime&quot; : &#123;</span><br><span class="line">        &quot;clusterTime&quot; : Timestamp(1565761959, 1),</span><br><span class="line">        &quot;signature&quot; : &#123;</span><br><span class="line">            &quot;hash&quot; : BinData(0,&quot;AAAAAAAAAAAAAAAAAAAAAAAAAAA&#x3D;&quot;),</span><br><span class="line">            &quot;keyId&quot; : NumberLong(0)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>说明：</p>
<ul>
<li><code>&quot;ok&quot; : 1</code> ：说明添加成功。</li>
</ul>
<p>查看副本集状态：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br></pre></td><td class="code"><pre><span class="line">myrs:PRIMARY&gt; rs.status()</span><br><span class="line">&#123;</span><br><span class="line">    &quot;set&quot; : &quot;myrs&quot;,</span><br><span class="line">    &quot;date&quot; : ISODate(&quot;2019-08-14T05:53:27.198Z&quot;),</span><br><span class="line">    &quot;myState&quot; : 1,</span><br><span class="line">    &quot;term&quot; : NumberLong(1),</span><br><span class="line">    &quot;syncingTo&quot; : &quot;&quot;,</span><br><span class="line">    &quot;syncSourceHost&quot; : &quot;&quot;,</span><br><span class="line">    &quot;syncSourceId&quot; : -1,</span><br><span class="line">    &quot;heartbeatIntervalMillis&quot; : NumberLong(2000),</span><br><span class="line">    &quot;optimes&quot; : &#123;</span><br><span class="line">        &quot;lastCommittedOpTime&quot; : &#123;</span><br><span class="line">            &quot;ts&quot; : Timestamp(1565761998, 1),</span><br><span class="line">            &quot;t&quot; : NumberLong(1)</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;readConcernMajorityOpTime&quot; : &#123;</span><br><span class="line">            &quot;ts&quot; : Timestamp(1565761998, 1),</span><br><span class="line">            &quot;t&quot; : NumberLong(1)</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;appliedOpTime&quot; : &#123;</span><br><span class="line">            &quot;ts&quot; : Timestamp(1565761998, 1),</span><br><span class="line">            &quot;t&quot; : NumberLong(1)</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;durableOpTime&quot; : &#123;</span><br><span class="line">            &quot;ts&quot; : Timestamp(1565761998, 1),</span><br><span class="line">            &quot;t&quot; : NumberLong(1)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    &quot;lastStableCheckpointTimestamp&quot; : Timestamp(1565761978, 1),</span><br><span class="line">    &quot;members&quot; : [</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;_id&quot; : 0,</span><br><span class="line">            &quot;name&quot; : &quot;180.76.159.126:27017&quot;,</span><br><span class="line">            &quot;health&quot; : 1,</span><br><span class="line">            &quot;state&quot; : 1,</span><br><span class="line">            &quot;stateStr&quot; : &quot;PRIMARY&quot;,</span><br><span class="line">            &quot;uptime&quot; : 1841,</span><br><span class="line">            &quot;optime&quot; : &#123;</span><br><span class="line">                &quot;ts&quot; : Timestamp(1565761998, 1),</span><br><span class="line">                &quot;t&quot; : NumberLong(1)</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;optimeDate&quot; : ISODate(&quot;2019-08-14T05:53:18Z&quot;),</span><br><span class="line">            &quot;syncingTo&quot; : &quot;&quot;,</span><br><span class="line">            &quot;syncSourceHost&quot; : &quot;&quot;,</span><br><span class="line">            &quot;syncSourceId&quot; : -1,</span><br><span class="line">            &quot;infoMessage&quot; : &quot;&quot;,</span><br><span class="line">            &quot;electionTime&quot; : Timestamp(1565760476, 2),</span><br><span class="line">            &quot;electionDate&quot; : ISODate(&quot;2019-08-14T05:27:56Z&quot;),</span><br><span class="line">            &quot;configVersion&quot; : 3,</span><br><span class="line">            &quot;self&quot; : true,</span><br><span class="line">            &quot;lastHeartbeatMessage&quot; : &quot;&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;_id&quot; : 1,</span><br><span class="line">            &quot;name&quot; : &quot;180.76.159.126:27018&quot;,</span><br><span class="line">            &quot;health&quot; : 1,</span><br><span class="line">            &quot;state&quot; : 2,</span><br><span class="line">            &quot;stateStr&quot; : &quot;SECONDARY&quot;,</span><br><span class="line">            &quot;uptime&quot; : 249,</span><br><span class="line">            &quot;optime&quot; : &#123;</span><br><span class="line">                &quot;ts&quot; : Timestamp(1565761998, 1),</span><br><span class="line">                &quot;t&quot; : NumberLong(1)</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;optimeDurable&quot; : &#123;</span><br><span class="line">                &quot;ts&quot; : Timestamp(1565761998, 1),</span><br><span class="line">                &quot;t&quot; : NumberLong(1)</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;optimeDate&quot; : ISODate(&quot;2019-08-14T05:53:18Z&quot;),</span><br><span class="line">            &quot;optimeDurableDate&quot; : ISODate(&quot;2019-08-14T05:53:18Z&quot;),</span><br><span class="line">            &quot;lastHeartbeat&quot; : ISODate(&quot;2019-08-14T05:53:25.668Z&quot;),</span><br><span class="line">            &quot;lastHeartbeatRecv&quot; : ISODate(&quot;2019-08-14T05:53:26.702Z&quot;),</span><br><span class="line">            &quot;pingMs&quot; : NumberLong(0),</span><br><span class="line">            &quot;lastHeartbeatMessage&quot; : &quot;&quot;,</span><br><span class="line">            &quot;syncingTo&quot; : &quot;180.76.159.126:27017&quot;,</span><br><span class="line">            &quot;syncSourceHost&quot; : &quot;180.76.159.126:27017&quot;,</span><br><span class="line">            &quot;syncSourceId&quot; : 0,</span><br><span class="line">            &quot;infoMessage&quot; : &quot;&quot;,</span><br><span class="line">            &quot;configVersion&quot; : 3</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;_id&quot; : 2,</span><br><span class="line">            &quot;name&quot; : &quot;180.76.159.126:27019&quot;,</span><br><span class="line">            &quot;health&quot; : 1,</span><br><span class="line">            &quot;state&quot; : 7,</span><br><span class="line">            &quot;stateStr&quot; : &quot;ARBITER&quot;,</span><br><span class="line">            &quot;uptime&quot; : 47,</span><br><span class="line">            &quot;lastHeartbeat&quot; : ISODate(&quot;2019-08-14T05:53:25.668Z&quot;),</span><br><span class="line">            &quot;lastHeartbeatRecv&quot; : ISODate(&quot;2019-08-14T05:53:25.685Z&quot;),</span><br><span class="line">            &quot;pingMs&quot; : NumberLong(0),</span><br><span class="line">            &quot;lastHeartbeatMessage&quot; : &quot;&quot;,</span><br><span class="line">            &quot;syncingTo&quot; : &quot;&quot;,</span><br><span class="line">            &quot;syncSourceHost&quot; : &quot;&quot;,</span><br><span class="line">            &quot;syncSourceId&quot; : -1,</span><br><span class="line">            &quot;infoMessage&quot; : &quot;&quot;,</span><br><span class="line">            &quot;configVersion&quot; : 3</span><br><span class="line">        &#125;</span><br><span class="line">    ],</span><br><span class="line">    &quot;ok&quot; : 1,</span><br><span class="line">    &quot;operationTime&quot; : Timestamp(1565761998, 1),</span><br><span class="line">    &quot;$clusterTime&quot; : &#123;</span><br><span class="line">        &quot;clusterTime&quot; : Timestamp(1565761998, 1),</span><br><span class="line">        &quot;signature&quot; : &#123;</span><br><span class="line">            &quot;hash&quot; : BinData(0,&quot;AAAAAAAAAAAAAAAAAAAAAAAAAAA&#x3D;&quot;),</span><br><span class="line">            &quot;keyId&quot; : NumberLong(0)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>说明：</p>
<ul>
<li><code>&quot;name&quot; : &quot;180.76.159.126:27019&quot;</code> 是第二个节点的名字，其角色是 <code>&quot;stateStr&quot; : &quot;ARBITER&quot;</code></li>
</ul>
<h2 id="1-5-副本集的数据读写操作"><a href="#1-5-副本集的数据读写操作" class="headerlink" title="1.5    副本集的数据读写操作"></a>1.5    副本集的数据读写操作</h2><p>目标：测试三个不同角色的节点的数据读写情况</p>
<p>登录主节点27017，写入和读取数据：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost ~]# &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongo --host 180.76.159.126 --port 27017</span><br><span class="line">myrs:PRIMARY&gt; use articledb</span><br><span class="line">switched to db articledb</span><br><span class="line">myrs:PRIMARY&gt; db</span><br><span class="line">articledb</span><br><span class="line">myrs:PRIMARY&gt; db.comment.insert(&#123;&quot;articleid&quot;:&quot;100000&quot;,&quot;content&quot;:&quot;今天天气真好，阳光明媚&quot;,&quot;userid&quot;:&quot;1001&quot;,&quot;nickname&quot;:&quot;Rose&quot;,&quot;createdatetime&quot;:new Date()&#125;)</span><br><span class="line">WriteResult(&#123; &quot;nInserted&quot; : 1 &#125;)</span><br><span class="line">myrs:PRIMARY&gt; db.comment.find()</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5d4d2ae3068138b4570f53bf&quot;), &quot;articleid&quot; : &quot;100000&quot;,&quot;content&quot; : &quot;今天天气真好，阳光明媚&quot;, &quot;userid&quot; : &quot;1001&quot;, &quot;nickname&quot; : &quot;Rose&quot;,&quot;createdatetime&quot; : ISODate(&quot;2019-08-09T08:12:19.427Z&quot;) &#125;</span><br></pre></td></tr></table></figure>

<p>登录从节点27018</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost ~]# &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongo --host 180.76.159.126 --port 27018</span><br><span class="line">myrs:SECONDARY&gt; show dbs;</span><br><span class="line">2019-09-10T10:56:51.953+0800 E QUERY  [js] Error: listDatabases failed:&#123;</span><br><span class="line">    &quot;operationTime&quot; : Timestamp(1568084204, 1),</span><br><span class="line">    &quot;ok&quot; : 0,</span><br><span class="line">    &quot;errmsg&quot; : &quot;not master and slaveOk&#x3D;false&quot;,</span><br><span class="line">    &quot;code&quot; : 13435,</span><br><span class="line">    &quot;codeName&quot; : &quot;NotMasterNoSlaveOk&quot;,</span><br><span class="line">    &quot;$clusterTime&quot; : &#123;</span><br><span class="line">        &quot;clusterTime&quot; : Timestamp(1568084204, 1),</span><br><span class="line">        &quot;signature&quot; : &#123;</span><br><span class="line">            &quot;hash&quot; : BinData(0,&quot;AAAAAAAAAAAAAAAAAAAAAAAAAAA&#x3D;&quot;),</span><br><span class="line">            &quot;keyId&quot; : NumberLong(0)</span><br><span class="line">       &#125;</span><br><span class="line">   &#125;</span><br><span class="line">&#125; :</span><br><span class="line">_getErrorWithCode@src&#x2F;mongo&#x2F;shell&#x2F;utils.js:25:13</span><br><span class="line">Mongo.prototype.getDBs@src&#x2F;mongo&#x2F;shell&#x2F;mongo.js:139:1</span><br><span class="line">shellHelper.show@src&#x2F;mongo&#x2F;shell&#x2F;utils.js:882:13</span><br><span class="line">shellHelper@src&#x2F;mongo&#x2F;shell&#x2F;utils.js:766:15</span><br><span class="line">@(shellhelp2):1:1</span><br></pre></td></tr></table></figure>

<p>发现，不能读取集合的数据。当前从节点只是一个备份，不是奴隶节点，无法读取数据，写当然更不行。</p>
<p>因为默认情况下，从节点是没有读写权限的，可以增加读的权限，但需要进行设置</p>
<p>设置读操作权限：</p>
<p>说明：</p>
<p>设置为奴隶节点，允许在从成员上运行读的操作</p>
<p>语法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">rs.slaveOk()</span><br><span class="line">#或</span><br><span class="line">rs.slaveOk(true)</span><br></pre></td></tr></table></figure>

<p>提示：</p>
<p>该命令是 <code>db.getMongo().setSlaveOk()</code> 的简化命令。</p>
<p>【示例】</p>
<p>在27018上设置作为奴隶节点权限，具备读权限：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs:SECONDARY&gt; rs.slaveOk()</span><br></pre></td></tr></table></figure>

<p>此时，在执行查询命令，运行成功！</p>
<p>但仍然不允许插入。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">myrs:SECONDARY&gt; rs.slaveOk()</span><br><span class="line">myrs:SECONDARY&gt; show dbs;</span><br><span class="line">admin    0.000GB</span><br><span class="line">articledb  0.000GB</span><br><span class="line">config   0.000GB</span><br><span class="line">local    0.000GB</span><br><span class="line">myrs:SECONDARY&gt; use articledb</span><br><span class="line">switched to db articledb</span><br><span class="line">myrs:SECONDARY&gt; show collections</span><br><span class="line">comment</span><br><span class="line">myrs:SECONDARY&gt; db.comment.find()</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5d7710c04cfd7eee2e3cdabe&quot;), &quot;articleid&quot; : &quot;100000&quot;,&quot;content&quot; : &quot;今天天气真好，阳光明媚&quot;, &quot;userid&quot; : &quot;1001&quot;, &quot;nickname&quot; : &quot;Rose&quot;,&quot;createdatetime&quot; : ISODate(&quot;2019-09-10T02:56:00.467Z&quot;) &#125;</span><br><span class="line">myrs:SECONDARY&gt; db.comment.insert(&#123;&quot;_id&quot;:&quot;1&quot;,&quot;articleid&quot;:&quot;100001&quot;,&quot;content&quot;:&quot;我们不应该把清晨浪费在手机上，健康很重要，k一杯温水幸福你我他。&quot;,&quot;userid&quot;:&quot;1002&quot;,&quot;nickname&quot;:&quot;相忘于江湖&quot;,&quot;createdatetime&quot;:new Date(&quot;2019-08-05T22:08:15.522Z&quot;),&quot;likenum&quot;:NumberInt(1000),&quot;state&quot;:&quot;1&quot;&#125;)</span><br><span class="line">WriteCommandError(&#123;</span><br><span class="line">    &quot;operationTime&quot; : Timestamp(1568084434, 1),</span><br><span class="line">    &quot;ok&quot; : 0,</span><br><span class="line">    &quot;errmsg&quot; : &quot;not master&quot;,</span><br><span class="line">    &quot;code&quot; : 10107,</span><br><span class="line">    &quot;codeName&quot; : &quot;NotMaster&quot;,</span><br><span class="line">    &quot;$clusterTime&quot; : &#123;</span><br><span class="line">        &quot;clusterTime&quot; : Timestamp(1568084434, 1),</span><br><span class="line">        &quot;signature&quot; : &#123;</span><br><span class="line">            &quot;hash&quot; : BinData(0,&quot;AAAAAAAAAAAAAAAAAAAAAAAAAAA&#x3D;&quot;),</span><br><span class="line">            &quot;keyId&quot; : NumberLong(0)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>现在可实现了读写分离，让主插入数据，让从来读取数据。</p>
<p>如果要取消作为奴隶节点的读权限：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">myrs:SECONDARY&gt; rs.slaveOk(false)</span><br><span class="line">myrs:SECONDARY&gt; db.comment.find()</span><br><span class="line">Error: error: &#123;</span><br><span class="line">    &quot;operationTime&quot; : Timestamp(1568084459, 1),</span><br><span class="line">    &quot;ok&quot; : 0,</span><br><span class="line">    &quot;errmsg&quot; : &quot;not master and slaveOk&#x3D;false&quot;,</span><br><span class="line">    &quot;code&quot; : 13435,</span><br><span class="line">    &quot;codeName&quot; : &quot;NotMasterNoSlaveOk&quot;,</span><br><span class="line">    &quot;$clusterTime&quot; : &#123;</span><br><span class="line">        &quot;clusterTime&quot; : Timestamp(1568084459, 1),</span><br><span class="line">        &quot;signature&quot; : &#123;</span><br><span class="line">            &quot;hash&quot; : BinData(0,&quot;AAAAAAAAAAAAAAAAAAAAAAAAAAA&#x3D;&quot;),</span><br><span class="line">            &quot;keyId&quot; : NumberLong(0)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>仲裁者节点，不存放任何业务数据的，可以登录查看</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost ~]# &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongo --host 180.76.159.126 --port 27019</span><br><span class="line">myrs:ARBITER&gt; rs.slaveOk()</span><br><span class="line">myrs:ARBITER&gt; show dbs</span><br><span class="line">local  0.000GB</span><br><span class="line">myrs:ARBITER&gt; use local</span><br><span class="line">switched to db local</span><br><span class="line">myrs:ARBITER&gt; show collections</span><br><span class="line">replset.minvalid</span><br><span class="line">replset.oplogTruncateAfterPoint</span><br><span class="line">startup_log</span><br><span class="line">system.replset</span><br><span class="line">system.rollback.id</span><br><span class="line">myrs:ARBITER&gt;</span><br></pre></td></tr></table></figure>

<p>发现，只存放副本集配置等数据。</p>
<h2 id="1-6-主节点的选举原则"><a href="#1-6-主节点的选举原则" class="headerlink" title="1.6    主节点的选举原则"></a>1.6    主节点的选举原则</h2><p>MongoDB在副本集中，会自动进行主节点的选举，主节点选举的触发条件：</p>
<ul>
<li>主节点故障</li>
<li>主节点网络不可达（默认心跳信息为10秒）</li>
<li>人工干预（rs.stepDown(600)）</li>
</ul>
<p>一旦触发选举，就要根据一定规则来选主节点。</p>
<p>选举规则是根据票数来决定谁获胜：</p>
<ul>
<li><p>票数最高，且获得了 “大多数”成员的投票支持的节点获胜。</p>
<p>“大多数”的定义为：假设复制集内投票成员数量为N，则大多数为 N/2 + 1。例如：3个投票成员，则大多数的值是2。当复制集内存活成员数量不足大多数时，整个复制集将无法选举出Primary，复制集将无法提供写服务，处于只读状态。</p>
</li>
<li><p>若票数相同，且都获得了 “大多数”成员的投票支持的，数据新的节点获胜。</p>
<p>数据的新旧是通过操作日志oplog来对比的。</p>
</li>
</ul>
<p>在获得票数的时候，优先级（priority）参数影响重大。</p>
<p>可以通过设置优先级（priority）来设置额外票数。优先级即权重，取值为0-1000，相当于可额外增加0-1000的票数，优先级的值越大，就越可能获得多数成员的投票（votes）数。指定较高的值可使成员更有资格成为主要成员，更低的值可使成员更不符合条件。</p>
<p>默认情况下，优先级的值是1</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line">myrs:PRIMARY&gt; rs.conf()</span><br><span class="line">&#123;</span><br><span class="line">    &quot;_id&quot; : &quot;myrs&quot;,</span><br><span class="line">    &quot;version&quot; : 3,</span><br><span class="line">    &quot;protocolVersion&quot; : NumberLong(1),</span><br><span class="line">    &quot;writeConcernMajorityJournalDefault&quot; : true,</span><br><span class="line">    &quot;members&quot; : [</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;_id&quot; : 0,</span><br><span class="line">            &quot;host&quot; : &quot;180.76.159.126:27017&quot;,</span><br><span class="line">            &quot;arbiterOnly&quot; : false,</span><br><span class="line">            &quot;buildIndexes&quot; : true,</span><br><span class="line">            &quot;hidden&quot; : false,</span><br><span class="line">            &quot;priority&quot; : 1,</span><br><span class="line">            &quot;tags&quot; : &#123;</span><br><span class="line">            </span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;slaveDelay&quot; : NumberLong(0),</span><br><span class="line">            &quot;votes&quot; : 1</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;_id&quot; : 1,</span><br><span class="line">            &quot;host&quot; : &quot;180.76.159.126:27018&quot;,</span><br><span class="line">            &quot;arbiterOnly&quot; : false,</span><br><span class="line">            &quot;buildIndexes&quot; : true,</span><br><span class="line">            &quot;hidden&quot; : false,</span><br><span class="line">            &quot;priority&quot; : 1,</span><br><span class="line">            &quot;tags&quot; : &#123;</span><br><span class="line">            </span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;slaveDelay&quot; : NumberLong(0),</span><br><span class="line">            &quot;votes&quot; : 1</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;_id&quot; : 2,</span><br><span class="line">            &quot;host&quot; : &quot;180.76.159.126:27019&quot;,</span><br><span class="line">            &quot;arbiterOnly&quot; : true,</span><br><span class="line">            &quot;buildIndexes&quot; : true,</span><br><span class="line">            &quot;hidden&quot; : false,</span><br><span class="line">            &quot;priority&quot; : 0,</span><br><span class="line">            &quot;tags&quot; : &#123;</span><br><span class="line">            </span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;slaveDelay&quot; : NumberLong(0),</span><br><span class="line">            &quot;votes&quot; : 1</span><br><span class="line">        &#125;</span><br><span class="line">    ],</span><br><span class="line">    &quot;settings&quot; : &#123;</span><br><span class="line">        &quot;chainingAllowed&quot; : true,</span><br><span class="line">        &quot;heartbeatIntervalMillis&quot; : 2000,</span><br><span class="line">        &quot;heartbeatTimeoutSecs&quot; : 10,</span><br><span class="line">        &quot;electionTimeoutMillis&quot; : 10000,</span><br><span class="line">        &quot;catchUpTimeoutMillis&quot; : -1,</span><br><span class="line">        &quot;catchUpTakeoverDelayMillis&quot; : 30000,</span><br><span class="line">        &quot;getLastErrorModes&quot; : &#123;</span><br><span class="line">        </span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;getLastErrorDefaults&quot; : &#123;</span><br><span class="line">            &quot;w&quot; : 1,</span><br><span class="line">            &quot;wtimeout&quot; : 0</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;replicaSetId&quot; : ObjectId(&quot;5d539bdcd6a308e600d126bb&quot;)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>可以看出，主节点和副本节点的优先级各为 1，即，默认可以认为都已经有了一票。但选举节点，优先级是0，（要注意是，官方说了，选举节点的优先级必须是0，不能是别的值。即不具备选举权，但具有投票权）</p>
<p>【了解】修改优先级</p>
<p>比如，下面提升从节点的优先级：</p>
<p>1）先将配置导入cfg变量</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">myrs:SECONDARY&gt; cfg&#x3D;rs.conf()</span><br></pre></td></tr></table></figure>

<p>2 ）然后修改值（ID号默认从0开始）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">myrs:SECONDARY&gt; cfg.members[1].priority&#x3D;2</span><br><span class="line">2</span><br></pre></td></tr></table></figure>

<p>3 ）重新加载配置</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">myrs:SECONDARY&gt; rs.reconfig(cfg)</span><br><span class="line">&#123; &quot;ok&quot; : 1 &#125;</span><br></pre></td></tr></table></figure>

<p>稍等片刻会重新开始选举。</p>
<h2 id="1-7-故障测试"><a href="#1-7-故障测试" class="headerlink" title="1.7    故障测试"></a>1.7    故障测试</h2><h3 id="1-7-1-副本节点故障测试"><a href="#1-7-1-副本节点故障测试" class="headerlink" title="1.7.1    副本节点故障测试"></a>1.7.1    副本节点故障测试</h3><p>关闭27018副本节点：</p>
<p>发现，主节点和仲裁节点对27018的心跳失败。因为主节点还在，因此，没有触发投票选举。</p>
<p>如果此时，在主节点写入数据。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">db.comment.insert(&#123;&quot;_id&quot;:&quot;1&quot;,&quot;articleid&quot;:&quot;100001&quot;,&quot;content&quot;:&quot;我们不应该把清晨浪费在手机上，健康很重要，一杯温水幸福你我他。&quot;,&quot;userid&quot;:&quot;1002&quot;,&quot;nickname&quot;:&quot;相忘于江湖&quot;,&quot;createdatetime&quot;:new Date(&quot;2019-08-05T22:08:15.522Z&quot;),&quot;likenum&quot;:NumberInt(1000),&quot;state&quot;:&quot;1&quot;&#125;)</span><br></pre></td></tr></table></figure>

<p>再启动从节点，会发现，主节点写入的数据，会自动同步给从节点。</p>
<h3 id="1-7-2-主节点故障测试"><a href="#1-7-2-主节点故障测试" class="headerlink" title="1.7.2    主节点故障测试"></a>1.7.2    主节点故障测试</h3><p>关闭27017节点</p>
<p>发现，从节点和仲裁节点对27017的心跳失败，当失败超过10秒，此时因为没有主节点了，会自动发起投票。</p>
<p>而副本节点只有27018，因此，候选人只有一个就是27018，开始投票。</p>
<p>27019向27018投了一票，27018本身自带一票，因此共两票，超过了“大多数”</p>
<p>27019是仲裁节点，没有选举权，27018不向其投票，其票数是0.</p>
<p>最终结果，27018成为主节点。具备读写功能。</p>
<p>在27018写入数据查看。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">db.comment.insert(&#123;&quot;_id&quot;:&quot;2&quot;,&quot;articleid&quot;:&quot;100001&quot;,&quot;content&quot;:&quot;我夏天空腹喝凉开水，冬天喝温开水&quot;,&quot;userid&quot;:&quot;1005&quot;,&quot;nickname&quot;:&quot;伊人憔悴&quot;,&quot;createdatetime&quot;:new Date(&quot;2019-08-05T23:58:51.485Z&quot;),&quot;likenum&quot;:NumberInt(888),&quot;state&quot;:&quot;1&quot;&#125;)</span><br></pre></td></tr></table></figure>

<p>再启动 27017节点，发现27017变成了从节点，27018仍保持主节点。</p>
<p>登录27017节点，发现是从节点了，数据自动从27018同步。</p>
<p>从而实现了高可用。</p>
<h3 id="1-7-3-仲裁节点和主节点故障"><a href="#1-7-3-仲裁节点和主节点故障" class="headerlink" title="1.7.3    仲裁节点和主节点故障"></a>1.7.3    仲裁节点和主节点故障</h3><p>先关掉仲裁节点27019，</p>
<p>关掉现在的主节点27018</p>
<p>登录27017后，发现，27017仍然是从节点，副本集中没有主节点了，导致此时，副本集是只读状态，无法写入。</p>
<p>为啥不选举了？因为27017的票数，没有获得大多数，即没有大于等于2，它只有默认的一票（优先级是1）</p>
<p>如果要触发选举，随便加入一个成员即可。</p>
<ul>
<li>如果只加入 27019仲裁节点成员，则主节点一定是27017，因为没得选了，仲裁节点不参与选举，但参与投票。（不演示）</li>
<li>如果只加入 27018节点，会发起选举。因为27017和27018都是两票，则按照谁数据新，谁当主节点。</li>
</ul>
<h3 id="1-7-4-仲裁节点和从节点故障"><a href="#1-7-4-仲裁节点和从节点故障" class="headerlink" title="1.7.4    仲裁节点和从节点故障"></a>1.7.4    仲裁节点和从节点故障</h3><p>先关掉仲裁节点27019，</p>
<p>关掉现在的副本节点27018</p>
<p>10秒后，27017主节点自动降级为副本节点。（服务降级）</p>
<p>副本集不可写数据了，已经故障了。</p>
<h2 id="1-8-Compass-连接副本集"><a href="#1-8-Compass-连接副本集" class="headerlink" title="1.8    Compass 连接副本集"></a>1.8    Compass 连接副本集</h2><p>compass连接：</p>
<p><img src="https://img-blog.csdnimg.cn/20200918165004924.png" alt="image-20200918102748168"></p>
<p><img src="https://img-blog.csdnimg.cn/202009181650221.png" alt="image-20200918102811874"></p>
<h2 id="1-9-SpringDataMongoDB-连接副本集"><a href="#1-9-SpringDataMongoDB-连接副本集" class="headerlink" title="1.9    SpringDataMongoDB 连接副本集"></a>1.9    SpringDataMongoDB 连接副本集</h2><p>副本集语法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mongodb:&#x2F;&#x2F;host1,host2,host3&#x2F;articledb?connect&#x3D;replicaSet&amp;slaveOk&#x3D;true&amp;replicaSet&#x3D;副本集名字</span><br></pre></td></tr></table></figure>

<p>其中：</p>
<ul>
<li>slaveOk=true ：开启副本节点读的功能，可实现读写分离。</li>
<li>connect=replicaSet ：自动到副本集中选择读写的主机。如果slaveOK是打开的，则实现了读写分离</li>
</ul>
<p>【示例】</p>
<p>连接 replica set 三台服务器 (端口 27017, 27018, 和27019)，直接连接第一个服务器，无论是replica set一部分或者主服务器或者从服务器，写入操作应用在主服务器 并且分布查询到从服务器。</p>
<p>修改配置文件application.yml</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">    <span class="comment">#数据源配置</span></span><br><span class="line">    <span class="attr">data:</span></span><br><span class="line">        <span class="attr">mongodb:</span></span><br><span class="line">            <span class="comment"># 主机地址</span></span><br><span class="line">            <span class="comment">#   host: 180.76.159.126</span></span><br><span class="line">            <span class="comment"># 数据库</span></span><br><span class="line">            <span class="comment">#   database: articledb</span></span><br><span class="line">            <span class="comment"># 默认端口是27017</span></span><br><span class="line">            <span class="comment">#   port: 27017</span></span><br><span class="line">            <span class="comment">#也可以使用uri连接</span></span><br><span class="line">            <span class="comment">#uri: mongodb://192.168.40.134:27017/articledb</span></span><br><span class="line">            <span class="comment"># 副本集的连接字符串</span></span><br><span class="line">            <span class="attr">uri:</span> <span class="string">mongodb://180.76.159.126:27017,180.76.159.126:27018,180.76.159.126:27019/articledb?connect=replicaSet&amp;slaveOk=true&amp;replicaSet=myrs</span></span><br></pre></td></tr></table></figure>

<p>注意：</p>
<p>主机必须是副本集中所有的主机，包括主节点、副本节点、仲裁节点。</p>
<p>SpringDataMongoDB自动实现了读写分离：</p>
<p>写操作时，只打开主节点连接；读操作是，同时打开主节点和从节点连接，但使用从节点获取数据。</p>
<p>完整的连接字符串的参考（了解）：</p>
<p>MongoDB客户端连接语法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mongodb:&#x2F;&#x2F;[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][&#x2F;[database][?options]]</span><br></pre></td></tr></table></figure>

<ul>
<li><strong>mongodb://</strong> 这是固定的格式，必须要指定。</li>
<li><strong>username:password@</strong> 可选项，如果设置，在连接数据库服务器之后，驱动都会尝试登陆这个数据库</li>
<li><strong>host1</strong> 必须的指定至少一个host, host1 是这个URI唯一要填写的。它指定了要连接服务器的地址。如果要连接复制集，请指定多个主机地址。</li>
<li><strong>portX</strong> 可选的指定端口，如果不填，默认为27017</li>
<li><strong>/database</strong> 如果指定username:password@，连接并验证登陆指定数据库。若不指定，默认打开test 数据库。</li>
<li><strong>?options</strong> 是连接选项。如果不使用/database，则前面需要加上/。所有连接选项都是键值对name=value，键值对之间通过&amp;或;（分号）隔开</li>
</ul>
<p>标准的连接格式包含了多个选项(options)，如下所示：</p>
<table>
<thead>
<tr>
<th>选项</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>replicaSet=name</td>
<td>验证replica set的名称。 Impliesconnect=replicaSet.</td>
</tr>
<tr>
<td>slaveOk=true|false</td>
<td>true:在connect=direct模式下，驱动会连接第一台机器，即使这台服务器不是主。在connect=replicaSet模式下，驱动会发送所有的写请求到主并且把读取操作分布在其他从服务器。false: 在connect=direct模式下，驱动会自动找寻主服务器. 在connect=replicaSet 模式下，驱动仅仅连接主服务器，并且所有的读写命令都连接到主服务器。</td>
</tr>
<tr>
<td>safe=true|false</td>
<td>true: 在执行更新操作之后，驱动都会发送getLastError命令来确保更新成功。(还要参考 wtimeoutMS).false: 在每次更新之后，驱动不会发送getLastError来确保更新成功。</td>
</tr>
<tr>
<td>w=n</td>
<td>驱动添加 { w : n } 到getLastError命令. 应用于safe=true。</td>
</tr>
<tr>
<td>wtimeoutMS=ms</td>
<td>驱动添加 { wtimeout : ms } 到 getlasterror 命令. 应用于 safe=true.</td>
</tr>
<tr>
<td>fsync=true|false</td>
<td>true: 驱动添加 { fsync : true } 到 getlasterror 命令.应用于safe=true.false: 驱动不会添加到getLastError命令中。</td>
</tr>
<tr>
<td>journal=true|false</td>
<td>如果设置为 true, 同步到 journal (在提交到数据库前写入到实体中).应用于 safe=true</td>
</tr>
<tr>
<td>connectTimeoutMS=ms</td>
<td>可以打开连接的时间</td>
</tr>
<tr>
<td>socketTimeoutMS=ms</td>
<td>发送和接受sockets的时间</td>
</tr>
</tbody></table>
<h1 id="2-分片集群-Sharded-Cluster"><a href="#2-分片集群-Sharded-Cluster" class="headerlink" title="2.    分片集群-Sharded Cluster"></a>2.    分片集群-Sharded Cluster</h1><h2 id="2-1-分片概念"><a href="#2-1-分片概念" class="headerlink" title="2.1    分片概念"></a>2.1    分片概念</h2><p>分片（sharding）是一种跨多台机器分布数据的方法， MongoDB使用分片来支持具有非常大的数据集和高吞吐量操作的部署。</p>
<p>换句话说：分片(sharding)是指将数据拆分，将其分散存在不同的机器上的过程。有时也用分区(partitioning)来表示这个概念。将数据分散到不同的机器上，不需要功能强大的大型计算机就可以储存更多的数据，处理更多的负载。</p>
<p>具有大型数据集或高吞吐量应用程序的数据库系统可以会挑战单个服务器的容量。例如，高查询率会耗尽服务器的CPU容量。工作集大小大于系统的RAM会强调磁盘驱动器的I / O容量。</p>
<p>有两种解决系统增长的方法：垂直扩展和水平扩展。</p>
<p>垂直扩展意味着增加单个服务器的容量，例如使用更强大的CPU，添加更多RAM或增加存储空间量。可用技术的局限性可能会限制单个机器对于给定工作负载而言足够强大。此外，基于云的提供商基于可用的硬件配置具有硬性上限。结果，垂直缩放有实际的最大值。</p>
<p>水平扩展意味着划分系统数据集并加载多个服务器，添加其他服务器以根据需要增加容量。虽然单个机器的总体速度或容量可能不高，但每台机器处理整个工作负载的子集，可能提供比单个高速大容量服务器更高的效率。扩展部署容量只需要根据需要添加额外的服务器，这可能比单个机器的高端硬件的总体成本更低。权衡是基础架构和部署维护的复杂性增加。</p>
<p>MongoDB支持通过分片进行水平扩展。</p>
<h2 id="2-2-分片集群包含的组件"><a href="#2-2-分片集群包含的组件" class="headerlink" title="2.2    分片集群包含的组件"></a>2.2    分片集群包含的组件</h2><p>MongoDB分片群集包含以下组件：</p>
<ul>
<li>分片（存储）：每个分片包含分片数据的子集。 每个分片都可以部署为副本集。</li>
<li>mongos （路由）：mongos充当查询路由器，在客户端应用程序和分片集群之间提供接口。</li>
<li>config servers （“调度”的配置）：配置服务器存储群集的元数据和配置设置。 从MongoDB 3.4开始，必须将配置服务器部署为副本集（CSRS）。</li>
</ul>
<p>下图描述了分片集群中组件的交互：</p>
<p><img src="https://img-blog.csdnimg.cn/20200918165044703.png" alt="image-20200918110216367"></p>
<p>MongoDB在集合级别对数据进行分片，将集合数据分布在集群中的分片上。</p>
<h2 id="2-3-分片集群架构目标"><a href="#2-3-分片集群架构目标" class="headerlink" title="2.3    分片集群架构目标"></a>2.3    分片集群架构目标</h2><p>两个分片节点副本集（3+3）+一个配置节点副本集（3）+两个路由节点（2），共11个服务节点。</p>
<p><img src="https://img-blog.csdnimg.cn/20200918165105108.png" alt="image-20200918110313173"></p>
<h2 id="2-4-分片（存储）节点副本集的创建"><a href="#2-4-分片（存储）节点副本集的创建" class="headerlink" title="2.4    分片（存储）节点副本集的创建"></a>2.4    分片（存储）节点副本集的创建</h2><p>所有的的配置文件都直接放到 sharded_cluster 的相应的子目录下面，默认配置文件名字：mongod.conf</p>
<h3 id="2-4-1-第一套副本集"><a href="#2-4-1-第一套副本集" class="headerlink" title="2.4.1    第一套副本集"></a>2.4.1    第一套副本集</h3><p>准备存放数据和日志的目录：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#-----------myshardrs01</span></span><br><span class="line">mkdir -p /mongodb/sharded_cluster/myshardrs01_27018/<span class="built_in">log</span> \ &amp;</span><br><span class="line">mkdir -p /mongodb/sharded_cluster/myshardrs01_27018/data/db \ &amp;</span><br><span class="line"></span><br><span class="line">mkdir -p /mongodb/sharded_cluster/myshardrs01_27118/<span class="built_in">log</span> \ &amp;</span><br><span class="line">mkdir -p /mongodb/sharded_cluster/myshardrs01_27118/data/db \ &amp;</span><br><span class="line"></span><br><span class="line">mkdir -p /mongodb/sharded_cluster/myshardrs01_27218/<span class="built_in">log</span> \ &amp;</span><br><span class="line">mkdir -p /mongodb/sharded_cluster/myshardrs01_27218/data/db</span><br></pre></td></tr></table></figure>

<p>新建或修改配置文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /mongodb/sharded_cluster/myshardrs01_27018/mongod.conf</span><br></pre></td></tr></table></figure>

<p>myshardrs01_27018 ：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">systemLog:</span></span><br><span class="line">    <span class="comment">#MongoDB发送所有日志输出的目标指定为文件</span></span><br><span class="line">    <span class="attr">destination:</span> <span class="string">file</span></span><br><span class="line">    <span class="comment">#mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径</span></span><br><span class="line">    <span class="attr">path:</span> <span class="string">"/mongodb/sharded_cluster/myshardrs01_27018/log/mongod.log"</span></span><br><span class="line">    <span class="comment">#当mongos或mongod实例重新启动时，mongos或mongod会将新条目附加到现有日志文件的末尾。</span></span><br><span class="line">    <span class="attr">logAppend:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">storage:</span></span><br><span class="line">    <span class="comment">#mongod实例存储其数据的目录。storage.dbPath设置仅适用于mongod。</span></span><br><span class="line">    <span class="attr">dbPath:</span> <span class="string">"/mongodb/sharded_cluster/myshardrs01_27018/data/db"</span></span><br><span class="line">    <span class="attr">journal:</span></span><br><span class="line">        <span class="comment">#启用或禁用持久性日志以确保数据文件保持有效和可恢复。</span></span><br><span class="line">        <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">processManagement:</span></span><br><span class="line">    <span class="comment">#启用在后台运行mongos或mongod进程的守护进程模式。</span></span><br><span class="line">    <span class="attr">fork:</span> <span class="literal">true</span></span><br><span class="line">    <span class="comment">#指定用于保存mongos或mongod进程的进程ID的文件位置，其中mongos或mongod将写入其PID</span></span><br><span class="line">    <span class="attr">pidFilePath:</span> <span class="string">"/mongodb/sharded_cluster/myshardrs01_27018/log/mongod.pid"</span></span><br><span class="line"><span class="attr">net:</span></span><br><span class="line">    <span class="comment">#服务实例绑定所有IP，有副作用，副本集初始化的时候，节点名字会自动设置为本地域名，而不是ip</span></span><br><span class="line">    <span class="comment">#bindIpAll: true</span></span><br><span class="line">    <span class="comment">#服务实例绑定的IP</span></span><br><span class="line">    <span class="attr">bindIp:</span> <span class="string">localhost,192.168.0.2</span></span><br><span class="line">    <span class="comment">#bindIp</span></span><br><span class="line">    <span class="comment">#绑定的端口</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">27018</span></span><br><span class="line"><span class="attr">replication:</span></span><br><span class="line">    <span class="comment">#副本集的名称</span></span><br><span class="line">    <span class="attr">replSetName:</span> <span class="string">myshardrs01</span></span><br><span class="line"><span class="attr">sharding:</span></span><br><span class="line">    <span class="comment">#分片角色</span></span><br><span class="line">    <span class="attr">clusterRole:</span> <span class="string">shardsvr</span></span><br></pre></td></tr></table></figure>

<p>sharding.clusterRole：</p>
<table>
<thead>
<tr>
<th>Value</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr>
<td>configsvr</td>
<td>Start this instance as a  config server. The instance starts on port  27019 by default.</td>
</tr>
<tr>
<td>shardsvr</td>
<td>Start this instance as a shard . The instance starts on port  27018 by default.</td>
</tr>
</tbody></table>
<p>注意：</p>
<p>设置sharding.clusterRole需要mongod实例运行复制。 要将实例部署为副本集成员，请使用replSetName设置并指定副本集的名称。</p>
<p>新建或修改配置文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /mongodb/sharded_cluster/myshardrs01_27118/mongod.conf</span><br></pre></td></tr></table></figure>

<p>myshardrs01_27118 ：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">systemLog:</span></span><br><span class="line">    <span class="comment">#MongoDB发送所有日志输出的目标指定为文件</span></span><br><span class="line">    <span class="attr">destination:</span> <span class="string">file</span></span><br><span class="line">    <span class="comment">#mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径</span></span><br><span class="line">    <span class="attr">path:</span> <span class="string">"/mongodb/sharded_cluster/myshardrs01_27118/log/mongod.log"</span></span><br><span class="line">    <span class="comment">#当mongos或mongod实例重新启动时，mongos或mongod会将新条目附加到现有日志文件的末尾。</span></span><br><span class="line">    <span class="attr">logAppend:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">storage:</span></span><br><span class="line">    <span class="comment">#mongod实例存储其数据的目录。storage.dbPath设置仅适用于mongod。</span></span><br><span class="line">    <span class="attr">dbPath:</span> <span class="string">"/mongodb/sharded_cluster/myshardrs01_27118/data/db"</span></span><br><span class="line">    <span class="attr">journal:</span></span><br><span class="line">        <span class="comment">#启用或禁用持久性日志以确保数据文件保持有效和可恢复。</span></span><br><span class="line">        <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">processManagement:</span></span><br><span class="line">    <span class="comment">#启用在后台运行mongos或mongod进程的守护进程模式。</span></span><br><span class="line">    <span class="attr">fork:</span> <span class="literal">true</span></span><br><span class="line">    <span class="comment">#指定用于保存mongos或mongod进程的进程ID的文件位置，其中mongos或mongod将写入其PID</span></span><br><span class="line">    <span class="attr">pidFilePath:</span> <span class="string">"/mongodb/sharded_cluster/myshardrs01_27118/log/mongod.pid"</span></span><br><span class="line"><span class="attr">net:</span></span><br><span class="line">    <span class="comment">#服务实例绑定所有IP</span></span><br><span class="line">    <span class="comment">#bindIpAll: true</span></span><br><span class="line">    <span class="comment">#服务实例绑定的IP</span></span><br><span class="line">    <span class="attr">bindIp:</span> <span class="string">localhost,192.168.0.2</span></span><br><span class="line">    <span class="comment">#绑定的端口</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">27118</span></span><br><span class="line"><span class="attr">replication:</span></span><br><span class="line">    <span class="attr">replSetName:</span> <span class="string">myshardrs01</span></span><br><span class="line"><span class="attr">sharding:</span></span><br><span class="line">    <span class="attr">clusterRole:</span> <span class="string">shardsvr</span></span><br></pre></td></tr></table></figure>

<p>新建或修改配置文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /mongodb/sharded_cluster/myshardrs01_27218/mongod.conf</span><br></pre></td></tr></table></figure>

<p>myshardrs01_27218 ：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">systemLog:</span></span><br><span class="line">    <span class="comment">#MongoDB发送所有日志输出的目标指定为文件</span></span><br><span class="line">    <span class="attr">destination:</span> <span class="string">file</span></span><br><span class="line">    <span class="comment">#mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径</span></span><br><span class="line">    <span class="attr">path:</span> <span class="string">"/mongodb/sharded_cluster/myshardrs01_27218/log/mongod.log"</span></span><br><span class="line">    <span class="comment">#当mongos或mongod实例重新启动时，mongos或mongod会将新条目附加到现有日志文件的末尾。</span></span><br><span class="line">    <span class="attr">logAppend:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">storage:</span></span><br><span class="line">    <span class="comment">#mongod实例存储其数据的目录。storage.dbPath设置仅适用于mongod。</span></span><br><span class="line">    <span class="attr">dbPath:</span> <span class="string">"/mongodb/sharded_cluster/myshardrs01_27218/data/db"</span></span><br><span class="line">    <span class="attr">journal:</span></span><br><span class="line">        <span class="comment">#启用或禁用持久性日志以确保数据文件保持有效和可恢复。</span></span><br><span class="line">        <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">processManagement:</span></span><br><span class="line">    <span class="comment">#启用在后台运行mongos或mongod进程的守护进程模式。</span></span><br><span class="line">    <span class="attr">fork:</span> <span class="literal">true</span></span><br><span class="line">    <span class="comment">#指定用于保存mongos或mongod进程的进程ID的文件位置，其中mongos或mongod将写入其PID</span></span><br><span class="line">    <span class="attr">pidFilePath:</span> <span class="string">"/mongodb/sharded_cluster/myshardrs01_27218/log/mongod.pid"</span></span><br><span class="line"><span class="attr">net:</span></span><br><span class="line">    <span class="comment">#服务实例绑定的IP</span></span><br><span class="line">    <span class="attr">bindIp:</span> <span class="string">localhost,192.168.0.2</span></span><br><span class="line">    <span class="comment">#绑定的端口</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">27218</span></span><br><span class="line"><span class="attr">replication:</span></span><br><span class="line">    <span class="attr">replSetName:</span> <span class="string">myshardrs01</span></span><br><span class="line"><span class="attr">sharding:</span></span><br><span class="line">    <span class="attr">clusterRole:</span> <span class="string">shardsvr</span></span><br></pre></td></tr></table></figure>

<p>启动第一套副本集：一主一副本一仲裁</p>
<p>依次启动三个mongod服务：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost bin]<span class="comment"># /usr/local/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs01_27018/mongod.conf</span></span><br><span class="line">about to fork child process, waiting until server is ready <span class="keyword">for</span> connections.</span><br><span class="line">forked process: 123223</span><br><span class="line">child process started successfully, parent exiting</span><br><span class="line"></span><br><span class="line">[root@bobohost bin]<span class="comment"># /usr/local/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs01_27118/mongod.conf</span></span><br><span class="line">about to fork child process, waiting until server is ready <span class="keyword">for</span> connections.</span><br><span class="line">forked process: 123292</span><br><span class="line">child process started successfully, parent exiting</span><br><span class="line"></span><br><span class="line">[root@bobohost bin]<span class="comment"># /usr/local/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs01_27218/mongod.conf</span></span><br><span class="line">about to fork child process, waiting until server is ready <span class="keyword">for</span> connections.</span><br><span class="line">forked process: 123326</span><br><span class="line">child process started successfully, parent exiting</span><br></pre></td></tr></table></figure>

<p>查看服务是否启动：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost bin]<span class="comment"># ps -ef |grep mongod</span></span><br><span class="line">polkitd  61622  61604  0 7月31 ?    00:04:29 mongod --bind_ip_all</span><br><span class="line">root   123223    1  1 01:10 ?     00:00:01 /usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs01_27018/mongod.conf</span><br><span class="line">root   123292    1  4 01:11 ?     00:00:00 /usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs01_27118/mongod.conf</span><br><span class="line">root   123326    1  6 01:11 ?     00:00:00 /usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs01_27218/mongod.conf</span><br></pre></td></tr></table></figure>

<h4 id="2-4-1-1-初始化副本集和创建主节点："><a href="#2-4-1-1-初始化副本集和创建主节点：" class="headerlink" title="2.4.1.1    初始化副本集和创建主节点："></a>2.4.1.1    初始化副本集和创建主节点：</h4><p>使用客户端命令连接任意一个节点，但这里尽量要连接主节点：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongo --host 180.76.159.126 --port 27018</span><br></pre></td></tr></table></figure>

<p>执行初始化副本集命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.initiate()</span><br></pre></td></tr></table></figure>

<p>查看副本集情况</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.status()</span><br></pre></td></tr></table></figure>

<p>主节点配置查看</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.conf()</span><br></pre></td></tr></table></figure>

<h4 id="2-4-1-2-添加副本节点"><a href="#2-4-1-2-添加副本节点" class="headerlink" title="2.4.1.2    添加副本节点"></a>2.4.1.2    添加副本节点</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.add(<span class="string">"180.76.159.126:27118"</span>)</span><br></pre></td></tr></table></figure>

<h4 id="2-4-1-3-添加仲裁节点"><a href="#2-4-1-3-添加仲裁节点" class="headerlink" title="2.4.1.3    添加仲裁节点"></a>2.4.1.3    添加仲裁节点</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.addArb(<span class="string">"180.76.159.126:27218"</span>)</span><br></pre></td></tr></table></figure>

<p>查看副本集的配置情况</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line">myshardrs01:PRIMARY&gt; rs.conf()</span><br><span class="line">&#123;</span><br><span class="line">    &quot;_id&quot; : &quot;myshardrs01&quot;,</span><br><span class="line">    &quot;version&quot; : 3,</span><br><span class="line">    &quot;protocolVersion&quot; : NumberLong(1),</span><br><span class="line">    &quot;writeConcernMajorityJournalDefault&quot; : true,</span><br><span class="line">    &quot;members&quot; : [</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;_id&quot; : 0,</span><br><span class="line">            &quot;host&quot; : &quot;180.76.159.126:27018&quot;,</span><br><span class="line">            &quot;arbiterOnly&quot; : false,</span><br><span class="line">            &quot;buildIndexes&quot; : true,</span><br><span class="line">            &quot;hidden&quot; : false,</span><br><span class="line">            &quot;priority&quot; : 1,</span><br><span class="line">            &quot;tags&quot; : &#123;</span><br><span class="line">            </span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;slaveDelay&quot; : NumberLong(0),</span><br><span class="line">            &quot;votes&quot; : 1</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;_id&quot; : 1,</span><br><span class="line">            &quot;host&quot; : &quot;180.76.159.126:27118&quot;,</span><br><span class="line">            &quot;arbiterOnly&quot; : false,</span><br><span class="line">            &quot;buildIndexes&quot; : true,</span><br><span class="line">            &quot;hidden&quot; : false,</span><br><span class="line">            &quot;priority&quot; : 1,</span><br><span class="line">            &quot;tags&quot; : &#123;</span><br><span class="line">            </span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;slaveDelay&quot; : NumberLong(0),</span><br><span class="line">            &quot;votes&quot; : 1</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;_id&quot; : 2,</span><br><span class="line">            &quot;host&quot; : &quot;180.76.159.126:27218&quot;,</span><br><span class="line">            &quot;arbiterOnly&quot; : true,</span><br><span class="line">            &quot;buildIndexes&quot; : true,</span><br><span class="line">            &quot;hidden&quot; : false,</span><br><span class="line">            &quot;priority&quot; : 0,</span><br><span class="line">            &quot;tags&quot; : &#123;</span><br><span class="line">            </span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;slaveDelay&quot; : NumberLong(0),</span><br><span class="line">            &quot;votes&quot; : 1</span><br><span class="line">        &#125;</span><br><span class="line">    ],</span><br></pre></td></tr></table></figure>

<h3 id="2-4-2-第二套副本集"><a href="#2-4-2-第二套副本集" class="headerlink" title="2.4.2    第二套副本集"></a>2.4.2    第二套副本集</h3><p>准备存放数据和日志的目录：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#-----------myshardrs02</span></span><br><span class="line">mkdir -p /mongodb/sharded_cluster/myshardrs02_27318/<span class="built_in">log</span> \ &amp;</span><br><span class="line">mkdir -p /mongodb/sharded_cluster/myshardrs02_27318/data/db \ &amp;</span><br><span class="line"></span><br><span class="line">mkdir -p /mongodb/sharded_cluster/myshardrs02_27418/<span class="built_in">log</span> \ &amp;</span><br><span class="line">mkdir -p /mongodb/sharded_cluster/myshardrs02_27418/data/db \ &amp;</span><br><span class="line"></span><br><span class="line">mkdir -p /mongodb/sharded_cluster/myshardrs02_27518/<span class="built_in">log</span> \ &amp;</span><br><span class="line">mkdir -p /mongodb/sharded_cluster/myshardrs02_27518/data/db</span><br></pre></td></tr></table></figure>

<p>新建或修改配置文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /mongodb/sharded_cluster/myshardrs02_27318/mongod.conf</span><br></pre></td></tr></table></figure>

<p>myshardrs02_27318 ：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">systemLog:</span></span><br><span class="line">    <span class="comment">#MongoDB发送所有日志输出的目标指定为文件</span></span><br><span class="line">    <span class="attr">destination:</span> <span class="string">file</span></span><br><span class="line">    <span class="comment">#mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径</span></span><br><span class="line">    <span class="attr">path:</span> <span class="string">"/mongodb/sharded_cluster/myshardrs02_27318/log/mongod.log"</span></span><br><span class="line">    <span class="comment">#当mongos或mongod实例重新启动时，mongos或mongod会将新条目附加到现有日志文件的末尾。</span></span><br><span class="line">    <span class="attr">logAppend:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">storage:</span></span><br><span class="line">    <span class="comment">#mongod实例存储其数据的目录。storage.dbPath设置仅适用于mongod。</span></span><br><span class="line">    <span class="attr">dbPath:</span> <span class="string">"/mongodb/sharded_cluster/myshardrs02_27318/data/db"</span></span><br><span class="line">    <span class="attr">journal:</span></span><br><span class="line">        <span class="comment">#启用或禁用持久性日志以确保数据文件保持有效和可恢复。</span></span><br><span class="line">        <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">processManagement:</span></span><br><span class="line">    <span class="comment">#启用在后台运行mongos或mongod进程的守护进程模式。</span></span><br><span class="line">    <span class="attr">fork:</span> <span class="literal">true</span></span><br><span class="line">    <span class="comment">#指定用于保存mongos或mongod进程的进程ID的文件位置，其中mongos或mongod将写入其PID</span></span><br><span class="line">    <span class="attr">pidFilePath:</span> <span class="string">"/mongodb/sharded_cluster/myshardrs02_27318/log/mongod.pid"</span></span><br><span class="line"><span class="attr">net:</span></span><br><span class="line">    <span class="comment">#服务实例绑定的IP</span></span><br><span class="line">    <span class="attr">bindIp:</span> <span class="string">localhost,192.168.0.2</span></span><br><span class="line">    <span class="comment">#绑定的端口</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">27318</span></span><br><span class="line"><span class="attr">replication:</span></span><br><span class="line">    <span class="attr">replSetName:</span> <span class="string">myshardrs02</span></span><br><span class="line"><span class="attr">sharding:</span></span><br><span class="line">    <span class="attr">clusterRole:</span> <span class="string">shardsvr</span></span><br></pre></td></tr></table></figure>

<p>新建或修改配置文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /mongodb/sharded_cluster/myshardrs02_27418/mongod.conf</span><br></pre></td></tr></table></figure>

<p>myshardrs02_27418 ：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">systemLog:</span></span><br><span class="line">    <span class="comment">#MongoDB发送所有日志输出的目标指定为文件</span></span><br><span class="line">    <span class="attr">destination:</span> <span class="string">file</span></span><br><span class="line">    <span class="comment">#mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径</span></span><br><span class="line">    <span class="attr">path:</span> <span class="string">"/mongodb/sharded_cluster/myshardrs02_27418/log/mongod.log"</span></span><br><span class="line">    <span class="comment">#当mongos或mongod实例重新启动时，mongos或mongod会将新条目附加到现有日志文件的末尾。</span></span><br><span class="line">    <span class="attr">logAppend:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">storage:</span></span><br><span class="line">    <span class="comment">#mongod实例存储其数据的目录。storage.dbPath设置仅适用于mongod。</span></span><br><span class="line">    <span class="attr">dbPath:</span> <span class="string">"/mongodb/sharded_cluster/myshardrs02_27418/data/db"</span></span><br><span class="line">    <span class="attr">journal:</span></span><br><span class="line">        <span class="comment">#启用或禁用持久性日志以确保数据文件保持有效和可恢复。</span></span><br><span class="line">        <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">processManagement:</span></span><br><span class="line">    <span class="comment">#启用在后台运行mongos或mongod进程的守护进程模式。</span></span><br><span class="line">    <span class="attr">fork:</span> <span class="literal">true</span></span><br><span class="line">    <span class="comment">#指定用于保存mongos或mongod进程的进程ID的文件位置，其中mongos或mongod将写入其PID</span></span><br><span class="line">    <span class="attr">pidFilePath:</span> <span class="string">"/mongodb/sharded_cluster/myshardrs02_27418/log/mongod.pid"</span></span><br><span class="line"><span class="attr">net:</span></span><br><span class="line">    <span class="comment">#服务实例绑定所有IP</span></span><br><span class="line">    <span class="comment">#bindIpAll: true</span></span><br><span class="line">    <span class="comment">#服务实例绑定的IP</span></span><br><span class="line">    <span class="attr">bindIp:</span> <span class="string">localhost,192.168.0.2</span></span><br><span class="line">    <span class="comment">#绑定的端口</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">27418</span></span><br><span class="line"><span class="attr">replication:</span></span><br><span class="line">    <span class="attr">replSetName:</span> <span class="string">myshardrs02</span></span><br><span class="line"><span class="attr">sharding:</span></span><br><span class="line">    <span class="attr">clusterRole:</span> <span class="string">shardsvr</span></span><br></pre></td></tr></table></figure>

<p>新建或修改配置文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /mongodb/sharded_cluster/myshardrs02_27518/mongod.conf</span><br></pre></td></tr></table></figure>

<p>myshardrs02_27518 ：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">systemLog:</span></span><br><span class="line">    <span class="comment">#MongoDB发送所有日志输出的目标指定为文件</span></span><br><span class="line">    <span class="attr">destination:</span> <span class="string">file</span></span><br><span class="line">    <span class="comment">#mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径</span></span><br><span class="line">    <span class="attr">path:</span> <span class="string">"/mongodb/sharded_cluster/myshardrs02_27518/log/mongod.log"</span></span><br><span class="line">    <span class="comment">#当mongos或mongod实例重新启动时，mongos或mongod会将新条目附加到现有日志文件的末尾。</span></span><br><span class="line">    <span class="attr">logAppend:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">storage:</span></span><br><span class="line">    <span class="comment">#mongod实例存储其数据的目录。storage.dbPath设置仅适用于mongod。</span></span><br><span class="line">    <span class="attr">dbPath:</span> <span class="string">"/mongodb/sharded_cluster/myshardrs02_27518/data/db"</span></span><br><span class="line">    <span class="attr">journal:</span></span><br><span class="line">        <span class="comment">#启用或禁用持久性日志以确保数据文件保持有效和可恢复。</span></span><br><span class="line">        <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">processManagement:</span></span><br><span class="line">    <span class="comment">#启用在后台运行mongos或mongod进程的守护进程模式。</span></span><br><span class="line">    <span class="attr">fork:</span> <span class="literal">true</span></span><br><span class="line">    <span class="comment">#指定用于保存mongos或mongod进程的进程ID的文件位置，其中mongos或mongod将写入其PID</span></span><br><span class="line">    <span class="attr">pidFilePath:</span> <span class="string">"/mongodb/sharded_cluster/myshardrs02_27518/log/mongod.pid"</span></span><br><span class="line"><span class="attr">net:</span></span><br><span class="line">    <span class="comment">#服务实例绑定所有IP</span></span><br><span class="line">    <span class="comment">#bindIpAll: true</span></span><br><span class="line">    <span class="comment">#服务实例绑定的IP</span></span><br><span class="line">    <span class="attr">bindIp:</span> <span class="string">localhost,192.168.0.2</span></span><br><span class="line">    <span class="comment">#绑定的端口</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">27518</span></span><br><span class="line"><span class="attr">replication:</span></span><br><span class="line">    <span class="attr">replSetName:</span> <span class="string">myshardrs02</span></span><br><span class="line"><span class="attr">sharding:</span></span><br><span class="line">    <span class="attr">clusterRole:</span> <span class="string">shardsvr</span></span><br></pre></td></tr></table></figure>

<p>启动第二套副本集：一主一副本一仲裁</p>
<p>依次启动三个mongod服务：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost bin]<span class="comment"># /usr/local/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs02_27318/mongod.conf</span></span><br><span class="line">about to fork child process, waiting until server is ready <span class="keyword">for</span> connections.</span><br><span class="line">forked process: 123223</span><br><span class="line">child process started successfully, parent exiting</span><br><span class="line"></span><br><span class="line">[root@bobohost bin]<span class="comment"># /usr/local/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs02_27418/mongod.conf</span></span><br><span class="line">about to fork child process, waiting until server is ready <span class="keyword">for</span> connections.</span><br><span class="line">forked process: 123292</span><br><span class="line">child process started successfully, parent exiting</span><br><span class="line"></span><br><span class="line">[root@bobohost bin]<span class="comment"># /usr/local/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs02_27518/mongod.conf</span></span><br><span class="line">about to fork child process, waiting until server is ready <span class="keyword">for</span> connections.</span><br><span class="line">forked process: 123326</span><br><span class="line">child process started successfully, parent exiting</span><br></pre></td></tr></table></figure>

<p>查看服务是否启动：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost bin]<span class="comment"># ps -ef |grep mongod</span></span><br></pre></td></tr></table></figure>

<h4 id="2-4-2-1-初始化副本集和创建主节点"><a href="#2-4-2-1-初始化副本集和创建主节点" class="headerlink" title="2.4.2.1    初始化副本集和创建主节点"></a>2.4.2.1    初始化副本集和创建主节点</h4><p>使用客户端命令连接任意一个节点，但这里尽量要连接主节点：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongo --host 180.76.159.126 --port 27318</span><br></pre></td></tr></table></figure>

<p>执行初始化副本集命令：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.initiate()</span><br></pre></td></tr></table></figure>

<p>查看副本集情况 (节选内容)：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.status()</span><br></pre></td></tr></table></figure>

<p>主节点配置查看：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.conf()</span><br></pre></td></tr></table></figure>

<h4 id="2-4-2-2-添加副本节点"><a href="#2-4-2-2-添加副本节点" class="headerlink" title="2.4.2.2    添加副本节点"></a>2.4.2.2    添加副本节点</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.add(&quot;180.76.159.126:27418&quot;)</span><br></pre></td></tr></table></figure>

<h4 id="2-4-2-3-添加仲裁节点"><a href="#2-4-2-3-添加仲裁节点" class="headerlink" title="2.4.2.3    添加仲裁节点"></a>2.4.2.3    添加仲裁节点</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.addArb(&quot;180.76.159.126:27518&quot;)</span><br></pre></td></tr></table></figure>

<p>查看副本集的配置情况</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br></pre></td><td class="code"><pre><span class="line">myshardrs02:PRIMARY&gt; rs.status()</span><br><span class="line">&#123;</span><br><span class="line">    &quot;set&quot; : &quot;myshardrs02&quot;,</span><br><span class="line">    &quot;date&quot; : ISODate(&quot;2019-07-31T21:38:22.463Z&quot;),</span><br><span class="line">    &quot;myState&quot; : 1,</span><br><span class="line">    &quot;term&quot; : NumberLong(1),</span><br><span class="line">    &quot;syncingTo&quot; : &quot;&quot;,</span><br><span class="line">    &quot;syncSourceHost&quot; : &quot;&quot;,</span><br><span class="line">    &quot;syncSourceId&quot; : -1,</span><br><span class="line">    &quot;heartbeatIntervalMillis&quot; : NumberLong(2000),</span><br><span class="line">    &quot;optimes&quot; : &#123;</span><br><span class="line">        &quot;lastCommittedOpTime&quot; : &#123;</span><br><span class="line">            &quot;ts&quot; : Timestamp(1564609094, 1),</span><br><span class="line">            &quot;t&quot; : NumberLong(1)</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;readConcernMajorityOpTime&quot; : &#123;</span><br><span class="line">            &quot;ts&quot; : Timestamp(1564609094, 1),</span><br><span class="line">            &quot;t&quot; : NumberLong(1)</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;appliedOpTime&quot; : &#123;</span><br><span class="line">            &quot;ts&quot; : Timestamp(1564609094, 1),</span><br><span class="line">            &quot;t&quot; : NumberLong(1)</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;durableOpTime&quot; : &#123;</span><br><span class="line">            &quot;ts&quot; : Timestamp(1564609094, 1),</span><br><span class="line">            &quot;t&quot; : NumberLong(1)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    &quot;lastStableCheckpointTimestamp&quot; : Timestamp(1564609074, 1),</span><br><span class="line">    &quot;members&quot; : [</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;_id&quot; : 0,</span><br><span class="line">            &quot;name&quot; : &quot;180.76.159.126:27318&quot;,</span><br><span class="line">            &quot;health&quot; : 1,</span><br><span class="line">            &quot;state&quot; : 1,</span><br><span class="line">            &quot;stateStr&quot; : &quot;PRIMARY&quot;,</span><br><span class="line">            &quot;uptime&quot; : 5086,</span><br><span class="line">            &quot;optime&quot; : &#123;</span><br><span class="line">                &quot;ts&quot; : Timestamp(1564609094, 1),</span><br><span class="line">                &quot;t&quot; : NumberLong(1)</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;optimeDate&quot; : ISODate(&quot;2019-07-31T21:38:14Z&quot;),</span><br><span class="line">            &quot;syncingTo&quot; : &quot;&quot;,</span><br><span class="line">            &quot;syncSourceHost&quot; : &quot;&quot;,</span><br><span class="line">            &quot;syncSourceId&quot; : -1,</span><br><span class="line">            &quot;infoMessage&quot; : &quot;&quot;,</span><br><span class="line">            &quot;electionTime&quot; : Timestamp(1564604032, 2),</span><br><span class="line">            &quot;electionDate&quot; : ISODate(&quot;2019-07-31T20:13:52Z&quot;),</span><br><span class="line">            &quot;configVersion&quot; : 3,</span><br><span class="line">            &quot;self&quot; : true,</span><br><span class="line">            &quot;lastHeartbeatMessage&quot; : &quot;&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;_id&quot; : 1,</span><br><span class="line">            &quot;name&quot; : &quot;180.76.159.126:27418&quot;,</span><br><span class="line">            &quot;health&quot; : 1,</span><br><span class="line">            &quot;state&quot; : 2,</span><br><span class="line">            &quot;stateStr&quot; : &quot;SECONDARY&quot;,</span><br><span class="line">            &quot;uptime&quot; : 4452,</span><br><span class="line">            &quot;optime&quot; : &#123;</span><br><span class="line">                &quot;ts&quot; : Timestamp(1564609094, 1),</span><br><span class="line">                &quot;t&quot; : NumberLong(1)</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;optimeDurable&quot; : &#123;</span><br><span class="line">                &quot;ts&quot; : Timestamp(1564609094, 1),</span><br><span class="line">                &quot;t&quot; : NumberLong(1)</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;optimeDate&quot; : ISODate(&quot;2019-07-31T21:38:14Z&quot;),</span><br><span class="line">            &quot;optimeDurableDate&quot; : ISODate(&quot;2019-07-31T21:38:14Z&quot;),</span><br><span class="line">            &quot;lastHeartbeat&quot; : ISODate(&quot;2019-07-31T21:38:21.178Z&quot;),</span><br><span class="line">            &quot;lastHeartbeatRecv&quot; : ISODate(&quot;2019-07-31T21:38:20.483Z&quot;),</span><br><span class="line">            &quot;pingMs&quot; : NumberLong(0),</span><br><span class="line">            &quot;lastHeartbeatMessage&quot; : &quot;&quot;,</span><br><span class="line">            &quot;syncingTo&quot; : &quot;180.76.159.126:27518&quot;,</span><br><span class="line">            &quot;syncSourceHost&quot; : &quot;180.76.159.126:27518&quot;,</span><br><span class="line">            &quot;syncSourceId&quot; : 2,</span><br><span class="line">            &quot;infoMessage&quot; : &quot;&quot;,</span><br><span class="line">            &quot;configVersion&quot; : 3</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;_id&quot; : 2,</span><br><span class="line">            &quot;name&quot; : &quot;180.76.159.126:27518&quot;,</span><br><span class="line">            &quot;health&quot; : 1,</span><br><span class="line">            &quot;state&quot; : 2,</span><br><span class="line">            &quot;stateStr&quot; : &quot;SECONDARY&quot;,</span><br><span class="line">            &quot;uptime&quot; : 4448,</span><br><span class="line">            &quot;optime&quot; : &#123;</span><br><span class="line">                &quot;ts&quot; : Timestamp(1564609094, 1),</span><br><span class="line">                &quot;t&quot; : NumberLong(1)</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;optimeDurable&quot; : &#123;</span><br><span class="line">                &quot;ts&quot; : Timestamp(1564609094, 1),</span><br><span class="line">                &quot;t&quot; : NumberLong(1)</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;optimeDate&quot; : ISODate(&quot;2019-07-31T21:38:14Z&quot;),</span><br><span class="line">            &quot;optimeDurableDate&quot; : ISODate(&quot;2019-07-31T21:38:14Z&quot;),</span><br><span class="line">            &quot;lastHeartbeat&quot; : ISODate(&quot;2019-07-31T21:38:21.178Z&quot;),</span><br><span class="line">            &quot;lastHeartbeatRecv&quot; : ISODate(&quot;2019-07-31T21:38:22.096Z&quot;),</span><br><span class="line">            &quot;pingMs&quot; : NumberLong(0),</span><br><span class="line">            &quot;lastHeartbeatMessage&quot; : &quot;&quot;,</span><br><span class="line">            &quot;syncingTo&quot; : &quot;180.76.159.126:27318&quot;,</span><br><span class="line">            &quot;syncSourceHost&quot; : &quot;180.76.159.126:27318&quot;,</span><br><span class="line">            &quot;syncSourceId&quot; : 0,</span><br><span class="line">            &quot;infoMessage&quot; : &quot;&quot;,</span><br><span class="line">            &quot;configVersion&quot; : 3</span><br><span class="line">        &#125;</span><br><span class="line">    ],</span><br></pre></td></tr></table></figure>

<h2 id="2-5-配置节点副本集的创建"><a href="#2-5-配置节点副本集的创建" class="headerlink" title="2.5    配置节点副本集的创建"></a>2.5    配置节点副本集的创建</h2><p>第一步：准备存放数据和日志的目录：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#-----------configrs</span></span><br><span class="line"><span class="comment">#建立数据节点data和日志目录</span></span><br><span class="line">mkdir -p /mongodb/sharded_cluster/myconfigrs_27019/<span class="built_in">log</span> \ &amp;</span><br><span class="line">mkdir -p /mongodb/sharded_cluster/myconfigrs_27019/data/db \ &amp;</span><br><span class="line"></span><br><span class="line">mkdir -p /mongodb/sharded_cluster/myconfigrs_27119/<span class="built_in">log</span> \ &amp;</span><br><span class="line">mkdir -p /mongodb/sharded_cluster/myconfigrs_27119/data/db \ &amp;</span><br><span class="line"></span><br><span class="line">mkdir -p /mongodb/sharded_cluster/myconfigrs_27219/<span class="built_in">log</span> \ &amp;</span><br><span class="line">mkdir -p /mongodb/sharded_cluster/myconfigrs_27219/data/db</span><br></pre></td></tr></table></figure>

<p>新建或修改配置文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /mongodb/sharded_cluster/myconfigrs_27019/mongod.conf</span><br></pre></td></tr></table></figure>

<p>myconfigrs_27019 ：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">systemLog:</span></span><br><span class="line">    <span class="comment">#MongoDB发送所有日志输出的目标指定为文件</span></span><br><span class="line">    <span class="attr">destination:</span> <span class="string">file</span></span><br><span class="line">    <span class="comment">#mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径</span></span><br><span class="line">    <span class="attr">path:</span> <span class="string">"/mongodb/sharded_cluster/myconfigrs_27019/log/mongod.log"</span></span><br><span class="line">    <span class="comment">#当mongos或mongod实例重新启动时，mongos或mongod会将新条目附加到现有日志文件的末尾。</span></span><br><span class="line">    <span class="attr">logAppend:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">storage:</span></span><br><span class="line">    <span class="comment">#mongod实例存储其数据的目录。storage.dbPath设置仅适用于mongod。</span></span><br><span class="line">    <span class="attr">dbPath:</span> <span class="string">"/mongodb/sharded_cluster/myconfigrs_27019/data/db"</span></span><br><span class="line">    <span class="attr">journal:</span></span><br><span class="line">        <span class="comment">#启用或禁用持久性日志以确保数据文件保持有效和可恢复。</span></span><br><span class="line">        <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">processManagement:</span></span><br><span class="line">    <span class="comment">#启用在后台运行mongos或mongod进程的守护进程模式。</span></span><br><span class="line">    <span class="attr">fork:</span> <span class="literal">true</span></span><br><span class="line">    <span class="comment">#指定用于保存mongos或mongod进程的进程ID的文件位置，其中mongos或mongod将写入其PID</span></span><br><span class="line">    <span class="attr">pidFilePath:</span> <span class="string">"/mongodb/sharded_cluster/myconfigrs_27019/log/mongod.pid"</span></span><br><span class="line"><span class="attr">net:</span></span><br><span class="line">    <span class="comment">#服务实例绑定所有IP</span></span><br><span class="line">    <span class="comment">#bindIpAll: true</span></span><br><span class="line">    <span class="comment">#服务实例绑定的IP</span></span><br><span class="line">    <span class="attr">bindIp:</span> <span class="string">localhost,192.168.0.2</span></span><br><span class="line">    <span class="comment">#绑定的端口</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">27019</span></span><br><span class="line"><span class="attr">replication:</span></span><br><span class="line">    <span class="attr">replSetName:</span> <span class="string">myconfigrs</span></span><br><span class="line"><span class="attr">sharding:</span></span><br><span class="line">    <span class="attr">clusterRole:</span> <span class="string">configsvr</span></span><br></pre></td></tr></table></figure>

<p>新建或修改配置文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /mongodb/sharded_cluster/myconfigrs_27119/mongod.conf</span><br></pre></td></tr></table></figure>

<p>myconfigrs_27119</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">systemLog:</span></span><br><span class="line">    <span class="comment">#MongoDB发送所有日志输出的目标指定为文件</span></span><br><span class="line">    <span class="attr">destination:</span> <span class="string">file</span></span><br><span class="line">    <span class="comment">#mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径</span></span><br><span class="line">    <span class="attr">path:</span> <span class="string">"/mongodb/sharded_cluster/myconfigrs_27119/log/mongod.log"</span></span><br><span class="line">    <span class="comment">#当mongos或mongod实例重新启动时，mongos或mongod会将新条目附加到现有日志文件的末尾。</span></span><br><span class="line">    <span class="attr">logAppend:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">storage:</span></span><br><span class="line">    <span class="comment">#mongod实例存储其数据的目录。storage.dbPath设置仅适用于mongod。</span></span><br><span class="line">    <span class="attr">dbPath:</span> <span class="string">"/mongodb/sharded_cluster/myconfigrs_27119/data/db"</span></span><br><span class="line">    <span class="attr">journal:</span></span><br><span class="line">        <span class="comment">#启用或禁用持久性日志以确保数据文件保持有效和可恢复。</span></span><br><span class="line">        <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">processManagement:</span></span><br><span class="line">    <span class="comment">#启用在后台运行mongos或mongod进程的守护进程模式。</span></span><br><span class="line">    <span class="attr">fork:</span> <span class="literal">true</span></span><br><span class="line">    <span class="comment">#指定用于保存mongos或mongod进程的进程ID的文件位置，其中mongos或mongod将写入其PID</span></span><br><span class="line">    <span class="attr">pidFilePath:</span> <span class="string">"/mongodb/sharded_cluster/myconfigrs_27119/log/mongod.pid"</span></span><br><span class="line"><span class="attr">net:</span></span><br><span class="line">    <span class="comment">#服务实例绑定所有IP</span></span><br><span class="line">    <span class="comment">#bindIpAll: true</span></span><br><span class="line">    <span class="comment">#服务实例绑定的IP</span></span><br><span class="line">    <span class="attr">bindIp:</span> <span class="string">localhost,192.168.0.2</span></span><br><span class="line">    <span class="comment">#绑定的端口</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">27119</span></span><br><span class="line"><span class="attr">replication:</span></span><br><span class="line">    <span class="attr">replSetName:</span> <span class="string">myconfigrs</span></span><br><span class="line"><span class="attr">sharding:</span></span><br><span class="line">    <span class="attr">clusterRole:</span> <span class="string">configsvr</span></span><br></pre></td></tr></table></figure>

<p>新建或修改配置文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /mongodb/sharded_cluster/myconfigrs_27219/mongod.conf</span><br></pre></td></tr></table></figure>

<p>myconfigrs_27219</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">systemLog:</span></span><br><span class="line">    <span class="comment">#MongoDB发送所有日志输出的目标指定为文件</span></span><br><span class="line">    <span class="attr">destination:</span> <span class="string">file</span></span><br><span class="line">    <span class="comment">#mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径</span></span><br><span class="line">    <span class="attr">path:</span> <span class="string">"/mongodb/sharded_cluster/myconfigrs_27219/log/mongod.log"</span></span><br><span class="line">    <span class="comment">#当mongos或mongod实例重新启动时，mongos或mongod会将新条目附加到现有日志文件的末尾。</span></span><br><span class="line">    <span class="attr">logAppend:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">storage:</span></span><br><span class="line">    <span class="comment">#mongod实例存储其数据的目录。storage.dbPath设置仅适用于mongod。</span></span><br><span class="line">    <span class="attr">dbPath:</span> <span class="string">"/mongodb/sharded_cluster/myconfigrs_27219/data/db"</span></span><br><span class="line">    <span class="attr">journal:</span></span><br><span class="line">        <span class="comment">#启用或禁用持久性日志以确保数据文件保持有效和可恢复。</span></span><br><span class="line">        <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">processManagement:</span></span><br><span class="line">    <span class="comment">#启用在后台运行mongos或mongod进程的守护进程模式。</span></span><br><span class="line">    <span class="attr">fork:</span> <span class="literal">true</span></span><br><span class="line">    <span class="comment">#指定用于保存mongos或mongod进程的进程ID的文件位置，其中mongos或mongod将写入其PID</span></span><br><span class="line">    <span class="attr">pidFilePath:</span> <span class="string">"/mongodb/sharded_cluster/myconfigrs_27219/log/mongod.pid"</span></span><br><span class="line"><span class="attr">net:</span></span><br><span class="line">    <span class="comment">#服务实例绑定所有IP</span></span><br><span class="line">    <span class="comment">#bindIpAll: true</span></span><br><span class="line">    <span class="comment">#服务实例绑定的IP</span></span><br><span class="line">    <span class="attr">bindIp:</span> <span class="string">localhost,192.168.0.2</span></span><br><span class="line">    <span class="comment">#绑定的端口</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">27219</span></span><br><span class="line"><span class="attr">replication:</span></span><br><span class="line">    <span class="attr">replSetName:</span> <span class="string">myconfigrs</span></span><br><span class="line"><span class="attr">sharding:</span></span><br><span class="line">    <span class="attr">clusterRole:</span> <span class="string">configsvr</span></span><br></pre></td></tr></table></figure>

<p>启动配置副本集：一主两副本</p>
<p>依次启动三个mongod服务：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost bin]<span class="comment"># /usr/local/mongodb/bin/mongod -f /mongodb/sharded_cluster/myconfigrs_27019/mongod.conf</span></span><br><span class="line">about to fork child process, waiting until server is ready <span class="keyword">for</span> connections.</span><br><span class="line">forked process: 123223</span><br><span class="line">child process started successfully, parent exiting</span><br><span class="line"></span><br><span class="line">[root@bobohost bin]<span class="comment"># /usr/local/mongodb/bin/mongod -f /mongodb/sharded_cluster/myconfigrs_27119/mongod.conf</span></span><br><span class="line">about to fork child process, waiting until server is ready <span class="keyword">for</span> connections.</span><br><span class="line">forked process: 123292</span><br><span class="line">child process started successfully, parent exiting</span><br><span class="line"></span><br><span class="line">[root@bobohost bin]<span class="comment"># /usr/local/mongodb/bin/mongod -f /mongodb/sharded_cluster/myconfigrs_27219/mongod.conf</span></span><br><span class="line">about to fork child process, waiting until server is ready <span class="keyword">for</span> connections.</span><br><span class="line">forked process: 123326</span><br><span class="line">child process started successfully, parent exiting</span><br></pre></td></tr></table></figure>

<p>查看服务是否启动：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost bin]<span class="comment"># ps -ef |grep mongod</span></span><br></pre></td></tr></table></figure>

<h3 id="2-5-1-初始化副本集和创建主节点"><a href="#2-5-1-初始化副本集和创建主节点" class="headerlink" title="2.5.1    初始化副本集和创建主节点"></a>2.5.1    初始化副本集和创建主节点</h3><p>使用客户端命令连接任意一个节点，但这里尽量要连接主节点：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongo --host 180.76.159.126 --port 27019</span><br></pre></td></tr></table></figure>

<p>执行初始化副本集命令：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.initiate()</span><br></pre></td></tr></table></figure>

<p>查看副本集情况 (节选内容)：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.status()</span><br></pre></td></tr></table></figure>

<p>主节点配置查看：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rs.conf()</span><br></pre></td></tr></table></figure>

<h3 id="2-5-2-添加两个副本节点"><a href="#2-5-2-添加两个副本节点" class="headerlink" title="2.5.2    添加两个副本节点"></a>2.5.2    添加两个副本节点</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">myshardrs01:PRIMARY&gt; rs.add(&quot;180.76.159.126:27119&quot;)</span><br><span class="line">myshardrs01:PRIMARY&gt; rs.add(&quot;180.76.159.126:27219&quot;)</span><br></pre></td></tr></table></figure>

<p>查看副本集的配置情况：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">myshardrs01:PRIMARY&gt; rs.conf()</span><br><span class="line">myshardrs01:PRIMARY&gt; rs.status()</span><br></pre></td></tr></table></figure>

<h2 id="2-6-路由节点的创建和操作"><a href="#2-6-路由节点的创建和操作" class="headerlink" title="2.6    路由节点的创建和操作"></a>2.6    路由节点的创建和操作</h2><h3 id="2-6-1-第一个路由节点的创建和连接"><a href="#2-6-1-第一个路由节点的创建和连接" class="headerlink" title="2.6.1    第一个路由节点的创建和连接"></a>2.6.1    第一个路由节点的创建和连接</h3><p>第一步：准备存放数据和日志的目录：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#-----------mongos01</span></span><br><span class="line">mkdir -p /mongodb/sharded_cluster/mymongos_27017/<span class="built_in">log</span></span><br></pre></td></tr></table></figure>

<p>mymongos_27017节点：</p>
<p>新建或修改配置文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vi /mongodb/sharded_cluster/mymongos_27017/mongos.conf</span><br></pre></td></tr></table></figure>

<p>mongos.conf：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">systemLog:</span></span><br><span class="line">    <span class="comment">#MongoDB发送所有日志输出的目标指定为文件</span></span><br><span class="line">    <span class="attr">destination:</span> <span class="string">file</span></span><br><span class="line">    <span class="comment">#mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径</span></span><br><span class="line">    <span class="attr">path:</span> <span class="string">"/mongodb/sharded_cluster/mymongos_27017/log/mongod.log"</span></span><br><span class="line">    <span class="comment">#当mongos或mongod实例重新启动时，mongos或mongod会将新条目附加到现有日志文件的末尾。</span></span><br><span class="line">    <span class="attr">logAppend:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">processManagement:</span></span><br><span class="line">    <span class="comment">#启用在后台运行mongos或mongod进程的守护进程模式。</span></span><br><span class="line">    <span class="attr">fork:</span> <span class="literal">true</span></span><br><span class="line">    <span class="comment">#指定用于保存mongos或mongod进程的进程ID的文件位置，其中mongos或mongod将写入其PID</span></span><br><span class="line">    <span class="attr">pidFilePath:</span> <span class="string">/mongodb/sharded_cluster/mymongos_27017/log/mongod.pid"</span></span><br><span class="line"><span class="attr">net:</span></span><br><span class="line">    <span class="comment">#服务实例绑定所有IP，有副作用，副本集初始化的时候，节点名字会自动设置为本地域名，而不是ip</span></span><br><span class="line">    <span class="comment">#bindIpAll: true</span></span><br><span class="line">    <span class="comment">#服务实例绑定的IP</span></span><br><span class="line">    <span class="attr">bindIp:</span> <span class="string">localhost,192.168.0.2</span></span><br><span class="line">    <span class="comment">#bindIp</span></span><br><span class="line">    <span class="comment">#绑定的端口</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">27017</span></span><br><span class="line"><span class="attr">sharding:</span></span><br><span class="line">    <span class="comment">#指定配置节点副本集</span></span><br><span class="line">    <span class="attr">configDB:</span> <span class="string">myconfigrs/180.76.159.126:27019,180.76.159.126:27119,180.76.159.126:27219</span></span><br></pre></td></tr></table></figure>

<p>启动mongos：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost bin]<span class="comment"># /usr/local/mongodb/bin/mongos -f /mongodb/sharded_cluster/mymongos_27017/mongos.conf</span></span><br><span class="line">about to fork child process, waiting until server is ready <span class="keyword">for</span> connections.</span><br><span class="line">forked process: 129874</span><br><span class="line">child process started successfully, parent exiting</span><br></pre></td></tr></table></figure>

<p>提示：启动如果失败，可以查看 log目录下的日志，查看失败原因。</p>
<p>客户端登录mongos</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongo --host 180.76.159.126 --port 27017</span><br></pre></td></tr></table></figure>

<p>此时，写不进去数据，如果写数据会报错：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">mongos&gt; use aadb</span><br><span class="line">switched to db aadb</span><br><span class="line">mongos&gt; db.aa.insert(&#123;aa:&quot;aa&quot;&#125;)</span><br><span class="line">WriteCommandError(&#123;</span><br><span class="line">    &quot;ok&quot; : 0,</span><br><span class="line">    &quot;errmsg&quot; : &quot;unable to initialize targeter for write op for collection aa.aa :: caused by :: Database aa not found :: caused by :: No shards found&quot;,</span><br><span class="line">    &quot;code&quot; : 70,</span><br><span class="line">    &quot;codeName&quot; : &quot;ShardNotFound&quot;,</span><br><span class="line">    &quot;operationTime&quot; : Timestamp(1564600123, 2),</span><br><span class="line">    &quot;$clusterTime&quot; : &#123;</span><br><span class="line">    &quot;clusterTime&quot; : Timestamp(1564600123, 2),</span><br><span class="line">        &quot;signature&quot; : &#123;</span><br><span class="line">            &quot;hash&quot; : BinData(0,&quot;AAAAAAAAAAAAAAAAAAAAAAAAAAA&#x3D;&quot;),</span><br><span class="line">            &quot;keyId&quot; : NumberLong(0)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>原因：通过路由节点操作，现在只是连接了配置节点，还没有连接分片数据节点，因此无法写入业务数据。</p>
<h3 id="2-6-2-在路由节点上进行分片配置操作"><a href="#2-6-2-在路由节点上进行分片配置操作" class="headerlink" title="2.6.2    在路由节点上进行分片配置操作"></a>2.6.2    在路由节点上进行分片配置操作</h3><p>使用命令添加分片：</p>
<h4 id="2-6-2-1-添加分片："><a href="#2-6-2-1-添加分片：" class="headerlink" title="2.6.2.1    添加分片："></a>2.6.2.1    添加分片：</h4><p>语法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sh.addShard(&quot;IP:Port&quot;)</span><br></pre></td></tr></table></figure>

<p>将第一套分片副本集添加进来：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">mongos&gt;sh.addShard(&quot;myshardrs01&#x2F;192.168.0.2:27018,180.76.159.126:27118,180.76.159.126:27218&quot;)</span><br><span class="line">&#123;</span><br><span class="line">    &quot;shardAdded&quot; : &quot;myshardrs01&quot;,</span><br><span class="line">    &quot;ok&quot; : 1,</span><br><span class="line">    &quot;operationTime&quot; : Timestamp(1564611970, 4),</span><br><span class="line">    &quot;$clusterTime&quot; : &#123;</span><br><span class="line">    &quot;clusterTime&quot; : Timestamp(1564611970, 4),</span><br><span class="line">        &quot;signature&quot; : &#123;</span><br><span class="line">            &quot;hash&quot; : BinData(0,&quot;AAAAAAAAAAAAAAAAAAAAAAAAAAA&#x3D;&quot;),</span><br><span class="line">            &quot;keyId&quot; : NumberLong(0)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>查看分片状态情况：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">mongos&gt; sh.status()</span><br><span class="line">--- Sharding Status ---</span><br><span class="line">    sharding version: &#123;</span><br><span class="line">        &quot;_id&quot; : 1,</span><br><span class="line">        &quot;minCompatibleVersion&quot; : 5,</span><br><span class="line">        &quot;currentVersion&quot; : 6,</span><br><span class="line">        &quot;clusterId&quot; : ObjectId(&quot;5d4211b798f3f9a48522c68b&quot;)</span><br><span class="line">    &#125;</span><br><span class="line">    shards:</span><br><span class="line">        &#123;  &quot;_id&quot; : &quot;myshardrs01&quot;,  &quot;host&quot; : &quot;myshardrs01&#x2F;180.76.159.126:27018,180.76.159.126:27118&quot;,  &quot;state&quot; : 1 &#125;</span><br><span class="line">    active mongoses:</span><br><span class="line">    	&quot;4.0.10&quot; : 1</span><br><span class="line">    autosplit:</span><br><span class="line">    	Currently enabled: yes</span><br><span class="line">    balancer:</span><br><span class="line">        Currently enabled:  yes</span><br><span class="line">        Currently running:  no</span><br><span class="line">        Failed balancer rounds in last 5 attempts:  0</span><br><span class="line">        Migration Results for the last 24 hours:</span><br><span class="line">        	No recent migrations</span><br><span class="line">    databases:</span><br><span class="line">    	&#123;  &quot;_id&quot; : &quot;config&quot;,  &quot;primary&quot; : &quot;config&quot;,  &quot;partitioned&quot; : true &#125;</span><br></pre></td></tr></table></figure>

<p>继续将第二套分片副本集添加进来：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">mongos&gt;sh.addShard(&quot;myshardrs02&#x2F;192.168.0.2:27318,180.76.159.126:27418,180.76.159.126:27518&quot;)</span><br><span class="line">&#123;</span><br><span class="line">    &quot;shardAdded&quot; : &quot;myshardrs02&quot;,</span><br><span class="line">    &quot;ok&quot; : 1,</span><br><span class="line">    &quot;operationTime&quot; : Timestamp(1564612147, 5),</span><br><span class="line">    &quot;$clusterTime&quot; : &#123;</span><br><span class="line">    &quot;clusterTime&quot; : Timestamp(1564612147, 5),</span><br><span class="line">        &quot;signature&quot; : &#123;</span><br><span class="line">            &quot;hash&quot; : BinData(0,&quot;AAAAAAAAAAAAAAAAAAAAAAAAAAA&#x3D;&quot;),</span><br><span class="line">            &quot;keyId&quot; : NumberLong(0)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>查看分片状态：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">mongos&gt; sh.status()</span><br><span class="line">--- Sharding Status ---</span><br><span class="line">    sharding version: &#123;</span><br><span class="line">        &quot;_id&quot; : 1,</span><br><span class="line">        &quot;minCompatibleVersion&quot; : 5,</span><br><span class="line">        &quot;currentVersion&quot; : 6,</span><br><span class="line">        &quot;clusterId&quot; : ObjectId(&quot;5d4211b798f3f9a48522c68b&quot;)</span><br><span class="line">    &#125;</span><br><span class="line">    shards:</span><br><span class="line">        &#123;  &quot;_id&quot; : &quot;myshardrs01&quot;,  &quot;host&quot; : &quot;myshardrs01&#x2F;180.76.159.126:27018,180.76.159.126:27118&quot;,  &quot;state&quot; : 1 &#125;</span><br><span class="line">        &#123;  &quot;_id&quot; : &quot;myshardrs02&quot;,  &quot;host&quot; : &quot;myshardrs02&#x2F;180.76.159.126:27318,180.76.159.126:27418&quot;,  &quot;state&quot; : 1 &#125;</span><br><span class="line">    active mongoses:</span><br><span class="line">    	&quot;4.0.10&quot; : 1</span><br><span class="line">    autosplit:</span><br><span class="line">    	Currently enabled: yes</span><br><span class="line">    balancer:</span><br><span class="line">        Currently enabled:  yes</span><br><span class="line">        Currently running:  no</span><br><span class="line">        Failed balancer rounds in last 5 attempts:  0</span><br><span class="line">        Migration Results for the last 24 hours:</span><br><span class="line">        	No recent migrations</span><br><span class="line">    databases:</span><br><span class="line">    	&#123;  &quot;_id&quot; : &quot;config&quot;,  &quot;primary&quot; : &quot;config&quot;,  &quot;partitioned&quot; : true &#125;</span><br></pre></td></tr></table></figure>

<p>提示：如果添加分片失败，需要先手动移除分片，检查添加分片的信息的正确性后，再次添加分片。</p>
<p>移除分片参考(了解)：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">use admin</span><br><span class="line">db.runCommand( &#123; removeShard: &quot;myshardrs02&quot; &#125; )</span><br></pre></td></tr></table></figure>

<p>注意：如果只剩下最后一个 shard，是无法删除的</p>
<p>移除时会自动转移分片数据，需要一个时间过程。</p>
<p>完成后，再次执行删除分片命令才能真正删除。</p>
<h4 id="2-6-2-2-开启分片功能"><a href="#2-6-2-2-开启分片功能" class="headerlink" title="2.6.2.2    开启分片功能"></a>2.6.2.2    开启分片功能</h4><p>sh.enableSharding(“库名”)、sh.shardCollection(“库名.集合名”,{“key”:1})</p>
<p>在mongos上的articledb数据库配置sharding:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">mongos&gt; sh.enableSharding(&quot;articledb&quot;)</span><br><span class="line">&#123;</span><br><span class="line">    &quot;ok&quot; : 1,</span><br><span class="line">    &quot;operationTime&quot; : Timestamp(1564612296, 5),</span><br><span class="line">    &quot;$clusterTime&quot; : &#123;</span><br><span class="line">        &quot;clusterTime&quot; : Timestamp(1564612296, 5),</span><br><span class="line">        &quot;signature&quot; : &#123;</span><br><span class="line">            &quot;hash&quot; : BinData(0,&quot;AAAAAAAAAAAAAAAAAAAAAAAAAAA&#x3D;&quot;),</span><br><span class="line">            &quot;keyId&quot; : NumberLong(0)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>查看分片状态：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">mongos&gt; sh.status()</span><br><span class="line">--- Sharding Status ---</span><br><span class="line">    sharding version: &#123;</span><br><span class="line">        &quot;_id&quot; : 1,</span><br><span class="line">        &quot;minCompatibleVersion&quot; : 5,</span><br><span class="line">        &quot;currentVersion&quot; : 6,</span><br><span class="line">        &quot;clusterId&quot; : ObjectId(&quot;5d4211b798f3f9a48522c68b&quot;)</span><br><span class="line">    &#125;</span><br><span class="line">    shards:</span><br><span class="line">        &#123;  &quot;_id&quot; : &quot;myshardrs01&quot;,  &quot;host&quot; : &quot;myshardrs01&#x2F;180.76.159.126:27018,180.76.159.126:27118&quot;,  &quot;state&quot; : 1 &#125;</span><br><span class="line">        &#123;  &quot;_id&quot; : &quot;myshardrs02&quot;,  &quot;host&quot; : &quot;myshardrs02&#x2F;180.76.159.126:27318,180.76.159.126:27418&quot;,  &quot;state&quot; : 1 &#125;</span><br><span class="line">    active mongoses:</span><br><span class="line">    	&quot;4.0.10&quot; : 1</span><br><span class="line">    autosplit:</span><br><span class="line">    	Currently enabled: yes</span><br><span class="line">    balancer:</span><br><span class="line">        Currently enabled:  yes</span><br><span class="line">        Currently running:  no</span><br><span class="line">        Failed balancer rounds in last 5 attempts:  0</span><br><span class="line">        Migration Results for the last 24 hours:</span><br><span class="line">        	No recent migrations</span><br><span class="line">    databases:</span><br><span class="line">        &#123;  &quot;_id&quot; : &quot;articledb&quot;,  &quot;primary&quot; : &quot;myshardrs02&quot;,  &quot;partitioned&quot; : true, &quot;version&quot; : &#123;  &quot;uuid&quot; : UUID(&quot;788c9a3b-bb6a-4cc2-a597-974694772986&quot;), &quot;lastMod&quot; : 1 &#125; &#125;</span><br><span class="line">        &#123;  &quot;_id&quot; : &quot;config&quot;,  &quot;primary&quot; : &quot;config&quot;,  &quot;partitioned&quot; : true &#125;</span><br><span class="line">            config.system.sessions</span><br><span class="line">                shard key: &#123; &quot;_id&quot; : 1 &#125;</span><br><span class="line">                unique: false</span><br><span class="line">                balancing: true</span><br><span class="line">                chunks:</span><br><span class="line">            		myshardrs01   1</span><br><span class="line">            	&#123; &quot;_id&quot; : &#123; &quot;$minKey&quot; : 1 &#125; &#125; --&gt;&gt; &#123; &quot;_id&quot; : &#123; &quot;$maxKey&quot; : 1 &#125; &#125; on : myshardrs01 Timestamp(1, 0)</span><br></pre></td></tr></table></figure>

<h4 id="2-6-2-3-集合分片"><a href="#2-6-2-3-集合分片" class="headerlink" title="2.6.2.3    集合分片"></a>2.6.2.3    集合分片</h4><p>对集合分片，你必须使用 sh.shardCollection() 方法指定集合和分片键</p>
<p>语法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sh.shardCollection(namespace, key, unique)</span><br></pre></td></tr></table></figure>

<p>参数：</p>
<table>
<thead>
<tr>
<th>Parameter</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr>
<td>namespace</td>
<td>string</td>
<td>要（分片）共享的目标集合的命名空间，格式： <database>.<collection></td>
</tr>
<tr>
<td>key</td>
<td>document</td>
<td>用作分片键的索引规范文档。shard键决定MongoDB如何在shard之间分发文档。除非集合为空，否则索引必须在shardcollection命令之前存在。如果集合为空，则MongoDB在对集合进行分片之前创建索引，前提是支持分片键的索引不存在。简单的说：由包含字段和该字段的索引遍历方向的文档组成。</td>
</tr>
<tr>
<td>unique</td>
<td>boolean</td>
<td>当值为true情况下，片键字段上会限制为确保是唯一索引。哈希策略片键不支持唯一索引。默认是false。</td>
</tr>
</tbody></table>
<p>对集合进行分片时,你需要选择一个 片键（Shard Key） , shard key 是每条记录都必须包含的,且建立了索引的单个字段或复合字段,MongoDB按照片键将数据划分到不同的 数据块 中,并将 数据块 均衡地分布到所有分片中.为了按照片键划分数据块,MongoDB使用 基于哈希的分片方式（随机平均分配）或者基于范围的分片方式（数值大小分配） 。</p>
<p>用什么字段当片键都可以，如：nickname作为片键，但一定是必填字段。</p>
<p><strong>分片规则一：哈希策略</strong></p>
<p>对于 基于哈希的分片 ,MongoDB计算一个字段的哈希值,并用这个哈希值来创建数据块.</p>
<p>在使用基于哈希分片的系统中,拥有”相近”片键的文档 很可能不会 存储在同一个数据块中,因此数据的分离性更好一些.</p>
<p>使用nickname作为片键，根据其值的哈希值进行数据分片</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">mongos&gt; sh.shardCollection(&quot;articledb.comment&quot;,&#123;&quot;nickname&quot;:&quot;hashed&quot;&#125;)</span><br><span class="line">&#123;</span><br><span class="line">    &quot;collectionsharded&quot; : &quot;articledb.comment&quot;,</span><br><span class="line">    &quot;collectionUUID&quot; : UUID(&quot;ddea6ed8-ee61-4693-bd16-196acc3a45e8&quot;),</span><br><span class="line">    &quot;ok&quot; : 1,</span><br><span class="line">    &quot;operationTime&quot; : Timestamp(1564612840, 28),</span><br><span class="line">    &quot;$clusterTime&quot; : &#123;</span><br><span class="line">        &quot;clusterTime&quot; : Timestamp(1564612840, 28),</span><br><span class="line">        &quot;signature&quot; : &#123;</span><br><span class="line">            &quot;hash&quot; : BinData(0,&quot;AAAAAAAAAAAAAAAAAAAAAAAAAAA&#x3D;&quot;),</span><br><span class="line">            &quot;keyId&quot; : NumberLong(0)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>查看分片状态：sh.status()</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"> databases:</span><br><span class="line"> &#123;  &quot;_id&quot; : &quot;articledb&quot;,  &quot;primary&quot; : &quot;myshardrs02&quot;,  &quot;partitioned&quot; : true,  &quot;version&quot; : &#123;  &quot;uuid&quot; : UUID(&quot;251436b7-86c2-4cd8-9a88-70874af29364&quot;), &quot;lastMod&quot; : 1 &#125; &#125;</span><br><span class="line">     articledb.comment</span><br><span class="line">         shard key: &#123; &quot;nickname&quot; : &quot;hashed&quot; &#125;</span><br><span class="line">         unique: false</span><br><span class="line">         balancing: true</span><br><span class="line">         chunks:</span><br><span class="line">             myshardrs01   2</span><br><span class="line">             myshardrs02   2</span><br><span class="line">         &#123; &quot;nickname&quot; : &#123; &quot;$minKey&quot; : 1 &#125; &#125; --&gt;&gt; &#123; &quot;nickname&quot; : NumberLong(&quot;-4611686018427387902&quot;) &#125; on : myshardrs01 Timestamp(1, 0)</span><br><span class="line">         &#123; &quot;nickname&quot; : NumberLong(&quot;-4611686018427387902&quot;) &#125; --&gt;&gt; &#123; &quot;nickname&quot; : NumberLong(0) &#125; on : myshardrs01 Timestamp(1, 1)</span><br><span class="line">         &#123; &quot;nickname&quot; : NumberLong(0) &#125; --&gt;&gt; &#123; &quot;nickname&quot; : NumberLong(&quot;4611686018427387902&quot;) &#125; on : myshardrs02 Timestamp(1, 2)</span><br><span class="line">         &#123; &quot;nickname&quot; : NumberLong(&quot;4611686018427387902&quot;) &#125; --&gt;&gt; &#123; &quot;nickname&quot; : &#123; &quot;$maxKey&quot; : 1 &#125; &#125; on : myshardrs02 Timestamp(1, 3)</span><br><span class="line"></span><br><span class="line">&#123;  &quot;_id&quot; : &quot;config&quot;,  &quot;primary&quot; : &quot;config&quot;,  &quot;partitioned&quot; : true &#125;</span><br><span class="line">    config.system.sessions</span><br><span class="line">        shard key: &#123; &quot;_id&quot; : 1 &#125;</span><br><span class="line">        unique: false</span><br><span class="line">        balancing: true</span><br><span class="line">        chunks:</span><br><span class="line">        	myshardrs01   1</span><br><span class="line">    	&#123; &quot;_id&quot; : &#123; &quot;$minKey&quot; : 1 &#125; &#125; --&gt;&gt; &#123; &quot;_id&quot; : &#123; &quot;$maxKey&quot; : 1 &#125; &#125; on : myshardrs01 Timestamp(1, 0)</span><br></pre></td></tr></table></figure>

<p><strong>分片规则二：范围策略</strong></p>
<p>对于 基于范围的分片 ,MongoDB按照片键的范围把数据分成不同部分.假设有一个数字的片键:想象一个从负无穷到正无穷的直线,每一个片键的值都在直线上画了一个点.MongoDB把这条直线划分为更短的不重叠的片段,并称之为 数据块 ,每个数据块包含了片键在一定范围内的数据.</p>
<p>在使用片键做范围划分的系统中,拥有”相近”片键的文档很可能存储在同一个数据块中,因此也会存储在同一个分片中.</p>
<p>如使用作者年龄字段作为片键，按照点赞数的值进行分片：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">mongos&gt; sh.shardCollection(&quot;articledb.author&quot;,&#123;&quot;age&quot;:1&#125;)</span><br><span class="line">&#123;</span><br><span class="line">    &quot;collectionsharded&quot; : &quot;articledb.author&quot;,</span><br><span class="line">    &quot;collectionUUID&quot; : UUID(&quot;9a47bdaa-213a-4039-9c18-e70bfc369df7&quot;),</span><br><span class="line">    &quot;ok&quot; : 1,</span><br><span class="line">    &quot;operationTime&quot; : Timestamp(1567512803, 13),</span><br><span class="line">    &quot;$clusterTime&quot; : &#123;</span><br><span class="line">        &quot;clusterTime&quot; : Timestamp(1567512803, 13),</span><br><span class="line">        &quot;signature&quot; : &#123;</span><br><span class="line">            &quot;hash&quot; : BinData(0,&quot;eE9QT5yE5sL1Tyr7+3U8GRy5+5Q&#x3D;&quot;),</span><br><span class="line">            &quot;keyId&quot; : NumberLong(&quot;6732061237309341726&quot;)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>注意的是：</p>
<ul>
<li>一个集合只能指定一个片键，否则报错。</li>
<li>一旦对一个集合分片，分片键和分片值就不可改变。 如：不能给集合选择不同的分片键、不能更新分片键的值。</li>
<li>根据age索引进行分配数据。</li>
</ul>
<p>查看分片状态：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">articledb.author</span><br><span class="line">    shard key: &#123; &quot;age&quot; : 1 &#125;</span><br><span class="line">    unique: false</span><br><span class="line">    balancing: true</span><br><span class="line">    chunks:</span><br><span class="line">    	myshardrs01 1</span><br><span class="line">    &#123; &quot;age&quot; : &#123; &quot;$minKey&quot; : 1 &#125; &#125; --&gt;&gt; &#123; &quot;age&quot; : &#123; &quot;$maxKey&quot; : 1 &#125; &#125; on : myshardrs01 Timestamp(1, 0)</span><br></pre></td></tr></table></figure>

<p>基于范围的分片方式与基于哈希的分片方式性能对比：</p>
<p>基于范围的分片方式提供了更高效的范围查询,给定一个片键的范围,分发路由可以很简单地确定哪个数据块存储了请求需要的数据,并将请求转发到相应的分片中.</p>
<p>不过,基于范围的分片会导致数据在不同分片上的不均衡,有时候,带来的消极作用会大于查询性能的积极作用.比如,如果片键所在的字段是线性增长的,一定时间内的所有请求都会落到某个固定的数据块中,最终导致分布在同一个分片中.在这种情况下,一小部分分片承载了集群大部分的数据,系统并不能很好地进行扩展.</p>
<p>与此相比,基于哈希的分片方式以范围查询性能的损失为代价,保证了集群中数据的均衡.哈希值的随机性使数据随机分布在每个数据块中,因此也随机分布在不同分片中.但是也正由于随机性,一个范围查询很难确定应该请求哪些分片,通常为了返回需要的结果,需要请求所有分片.</p>
<p>如无特殊情况，一般推荐使用 Hash Sharding。</p>
<p>而使用 _id 作为片键是一个不错的选择，因为它是必有的，你可以使用数据文档 _id 的哈希作为片键。</p>
<p>这个方案能够是的读和写都能够平均分布，并且它能够保证每个文档都有不同的片键所以数据块能够很精细。</p>
<p>似乎还是不够完美，因为这样的话对多个文档的查询必将命中所有的分片。虽说如此，这也是一种比较好的方案了。</p>
<p>理想化的 shard key 可以让 documents 均匀地在集群中分布：</p>
<p><img src="https://img-blog.csdnimg.cn/2020091816513874.png" alt="image-20200918121206254"></p>
<p>显示集群的详细信息：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mongos&gt; db.printShardingStatus()</span><br></pre></td></tr></table></figure>

<p>查看均衡器是否工作（需要重新均衡时系统才会自动启动，不用管它）：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mongos&gt; sh.isBalancerRunning()</span><br><span class="line">false</span><br></pre></td></tr></table></figure>

<p>查看当前 Balancer状态：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mongos&gt; sh.getBalancerState()</span><br><span class="line">true</span><br></pre></td></tr></table></figure>

<h3 id="2-6-3-分片后插入数据测试"><a href="#2-6-3-分片后插入数据测试" class="headerlink" title="2.6.3    分片后插入数据测试"></a>2.6.3    分片后插入数据测试</h3><p>测试一（哈希规则）：登录mongs后，向comment循环插入1000条数据做测试：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">mongos&gt; use articledb</span><br><span class="line">switched to db articledb</span><br><span class="line">mongos&gt; for(var i&#x3D;1;i&lt;&#x3D;1000;i++)&#123;db.comment.insert(&#123;_id:i+&quot;&quot;,nickname:&quot;BoBo&quot;+i&#125;)&#125;</span><br><span class="line">WriteResult(&#123; &quot;nInserted&quot; : 1 &#125;)</span><br><span class="line">mongos&gt; db.comment.count()</span><br><span class="line">1000</span><br></pre></td></tr></table></figure>

<p>提示： js的语法，因为mongo的shell是一个JavaScript的shell。</p>
<p>注意：从路由上插入的数据，必须包含片键，否则无法插入。</p>
<p>分别登陆两个片的主节点，统计文档数量</p>
<p>第一个分片副本集：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongo --host 180.76.159.126 --port 27018</span><br><span class="line"></span><br><span class="line">myshardrs01:PRIMARY&gt; use articledb</span><br><span class="line">switched to db articledb</span><br><span class="line">myshardrs01:PRIMARY&gt; db.comment.count()</span><br><span class="line">507</span><br></pre></td></tr></table></figure>

<p>第二个分片副本集：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongo --host 180.76.159.126 --port 27318</span><br><span class="line"></span><br><span class="line">myshardrs02:PRIMARY&gt; use articledb</span><br><span class="line">switched to db articledb</span><br><span class="line">myshardrs02:PRIMARY&gt; db.comment.count()</span><br><span class="line">493</span><br></pre></td></tr></table></figure>

<p>可以看到， 1000条数据近似均匀的分布到了2个shard上。是根据片键的哈希值分配的。</p>
<p>这种分配方式非常易于水平扩展：一旦数据存储需要更大空间，可以直接再增加分片即可，同时提升了性能。</p>
<p>使用db.comment.stats()查看单个集合的完整情况，mongos执行该命令可以查看该集合的数据分片的情况。</p>
<p>使用sh.status()查看本库内所有集合的分片信息。</p>
<p>测试二（范围规则）：登录mongs后，向comment循环插入1000条数据做测试：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">mongos&gt; use articledb</span><br><span class="line">switched to db articledb</span><br><span class="line">mongos&gt; for(var i&#x3D;1;i&lt;&#x3D;20000;i++)&#123;db.author.save(&#123;&quot;name&quot;:&quot;BoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBoBo&quot;+i,&quot;age&quot;:NumberInt(i%120)&#125;)&#125;</span><br><span class="line">WriteResult(&#123; &quot;nInserted&quot; : 1 &#125;)</span><br><span class="line">mongos&gt; db.comment.count()</span><br><span class="line">20000</span><br></pre></td></tr></table></figure>

<p>插入成功后，仍然要分别查看两个分片副本集的数据情况。</p>
<p>分片效果：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">articledb.author</span><br><span class="line">    shard key: &#123; &quot;age&quot; : 1 &#125;</span><br><span class="line">    unique: false</span><br><span class="line">    balancing: true</span><br><span class="line">    chunks:</span><br><span class="line">        myshardrs01 2</span><br><span class="line">        myshardrs02 1</span><br><span class="line">    &#123; &quot;age&quot; : &#123; &quot;$minKey&quot; : 1 &#125; &#125; --&gt;&gt; &#123; &quot;age&quot; : 0 &#125; on : myshardrs02 Timestamp(2, 0)</span><br><span class="line">    &#123; &quot;age&quot; : 0 &#125; --&gt;&gt; &#123; &quot;age&quot; : 112 &#125; on : myshardrs01 Timestamp(2, 1)</span><br><span class="line">    &#123; &quot;age&quot; : 112 &#125; --&gt;&gt; &#123; &quot;age&quot; : &#123; &quot;$maxKey&quot; : 1 &#125; &#125; on : myshardrs01 Timestamp(1, 3)</span><br></pre></td></tr></table></figure>

<p>提示：</p>
<p>如果查看状态发现没有分片，则可能是由于以下原因造成了：</p>
<ul>
<li><p>系统繁忙，正在分片中。</p>
</li>
<li><p>数据块（chunk）没有填满，默认的数据块尺寸（chunksize）是64M，填满后才会考虑向其他片的数据块填充数据，因此，为了测试，可以将其改小，这里改为1M，操作如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">use config</span><br><span class="line">db.settings.save( &#123; _id:&quot;chunksize&quot;, value: 1 &#125; )</span><br></pre></td></tr></table></figure>

<p>测试完改回来：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">db.settings.save( &#123; _id:&quot;chunksize&quot;, value: 64 &#125; )</span><br></pre></td></tr></table></figure>

</li>
</ul>
<p>注意：要先改小，再设置分片。为了测试，可以先删除集合，重新建立集合的分片策略，再插入数据测试即可。</p>
<h3 id="2-6-4-再增加一个路由节点"><a href="#2-6-4-再增加一个路由节点" class="headerlink" title="2.6.4    再增加一个路由节点"></a>2.6.4    再增加一个路由节点</h3><p>文件夹：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#-----------mongos02</span></span><br><span class="line">mkdir -p /mongodb/sharded_cluster/mymongos_27117/<span class="built_in">log</span></span><br></pre></td></tr></table></figure>

<p>新建或修改配置文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vi /mongodb/sharded_cluster/mymongos_27117/mongos.conf</span><br></pre></td></tr></table></figure>

<p>mongos.conf：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">systemLog:</span></span><br><span class="line">    <span class="comment">#MongoDB发送所有日志输出的目标指定为文件</span></span><br><span class="line">    <span class="attr">destination:</span> <span class="string">file</span></span><br><span class="line">    <span class="comment">#mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径</span></span><br><span class="line">    <span class="attr">path:</span> <span class="string">"/mongodb/sharded_cluster/mymongos_27117/log/mongod.log"</span></span><br><span class="line">    <span class="comment">#当mongos或mongod实例重新启动时，mongos或mongod会将新条目附加到现有日志文件的末尾。</span></span><br><span class="line">    <span class="attr">logAppend:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">processManagement:</span></span><br><span class="line">    <span class="comment">#启用在后台运行mongos或mongod进程的守护进程模式。</span></span><br><span class="line">    <span class="attr">fork:</span> <span class="literal">true</span></span><br><span class="line">    <span class="comment">#指定用于保存mongos或mongod进程的进程ID的文件位置，其中mongos或mongod将写入其PID</span></span><br><span class="line">    <span class="attr">pidFilePath:</span> <span class="string">/mongodb/sharded_cluster/mymongos_27117/log/mongod.pid"</span></span><br><span class="line"><span class="attr">net:</span></span><br><span class="line">    <span class="comment">#服务实例绑定所有IP，有副作用，副本集初始化的时候，节点名字会自动设置为本地域名，而不是ip</span></span><br><span class="line">    <span class="comment">#bindIpAll: true</span></span><br><span class="line">    <span class="comment">#服务实例绑定的IP</span></span><br><span class="line">    <span class="attr">bindIp:</span> <span class="string">localhost,192.168.0.2</span></span><br><span class="line">    <span class="comment">#bindIp</span></span><br><span class="line">    <span class="comment">#绑定的端口</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">27117</span></span><br><span class="line"><span class="attr">sharding:</span></span><br><span class="line">    <span class="attr">configDB:</span> <span class="string">myconfigrs/180.76.159.126:27019,180.76.159.126:27119,180.76.159.126:27219</span></span><br></pre></td></tr></table></figure>

<p>启动mongos2：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost bin]# &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongos -f &#x2F;mongodb&#x2F;sharded_cluster&#x2F;mymongos_27117&#x2F;mongos.conf</span><br><span class="line">about to fork child process, waiting until server is ready for connections.</span><br><span class="line">forked process: 129874</span><br><span class="line">child process started successfully, parent exiting</span><br></pre></td></tr></table></figure>

<p>使用mongo客户端登录27117，发现，第二个路由无需配置，因为分片配置都保存到了配置服务器中了。</p>
<h2 id="2-7-Compass-连接分片集群"><a href="#2-7-Compass-连接分片集群" class="headerlink" title="2.7    Compass 连接分片集群"></a>2.7    Compass 连接分片集群</h2><p>compass连接：</p>
<p><img src="https://img-blog.csdnimg.cn/2020091816515942.png" alt="image-20200918122259273"></p>
<p>提示：和连接单机 mongod一样。</p>
<p>连接成功后，上方有mongos和分片集群的提示：</p>
<p><img src="https://img-blog.csdnimg.cn/20200918165217814.png" alt="image-20200918122329943"></p>
<h2 id="2-8-SpringDataMongDB-连接分片集群"><a href="#2-8-SpringDataMongDB-连接分片集群" class="headerlink" title="2.8    SpringDataMongDB 连接分片集群"></a>2.8    SpringDataMongDB 连接分片集群</h2><p>Java客户端常用的是SpringDataMongoDB，其连接的是mongs路由，配置和单机mongod的配置是一样的。</p>
<p>多个路由的时候的SpringDataMongoDB的客户端配置参考如下：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">    <span class="comment">#数据源配置</span></span><br><span class="line">    <span class="attr">data:</span></span><br><span class="line">        <span class="attr">mongodb:</span></span><br><span class="line">            <span class="comment"># 主机地址</span></span><br><span class="line">            <span class="comment">#   host: 180.76.159.126</span></span><br><span class="line">            <span class="comment"># 数据库</span></span><br><span class="line">            <span class="comment">#   database: articledb</span></span><br><span class="line">            <span class="comment"># 默认端口是27017</span></span><br><span class="line">            <span class="comment">#   port: 27017</span></span><br><span class="line">            <span class="comment">#也可以使用uri连接</span></span><br><span class="line">            <span class="comment">#   uri: mongodb://192.168.40.134:28017/articledb</span></span><br><span class="line">            <span class="comment"># 连接副本集字符串</span></span><br><span class="line">            <span class="comment">#   uri: mongodb://180.76.159.126:27017,180.76.159.126:27018,180.76.159.126:27019/articledb?connect=replicaSet&amp;slaveOk=true&amp;replicaSet=myrs</span></span><br><span class="line">            <span class="comment">#连接路由字符串</span></span><br><span class="line">            <span class="attr">uri:</span> <span class="string">mongodb://180.76.159.126:27017,180.76.159.126:27117/articledb</span></span><br></pre></td></tr></table></figure>

<p>通过日志发现，写入数据的时候，会选择一个路由写入</p>
<h2 id="2-9-清除所有的节点数据（备用）"><a href="#2-9-清除所有的节点数据（备用）" class="headerlink" title="2.9    清除所有的节点数据（备用）"></a>2.9    清除所有的节点数据（备用）</h2><p>如果在搭建分片的时候有操作失败或配置有问题，需要重新来过的，可以进行如下操作：</p>
<p>第一步：查询出所有的测试服务节点的进程：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost sharded_cluster]# ps -ef |grep mongo</span><br><span class="line">root    10184    1  0 06:04 ?     00:01:25 &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod -f &#x2F;mongodb&#x2F;sharded_cluster&#x2F;myshardrs01_27018&#x2F;mongod.conf</span><br><span class="line">root    10219    1  0 06:04 ?     00:01:25 &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod -f &#x2F;mongodb&#x2F;sharded_cluster&#x2F;myshardrs01_27118&#x2F;mongod.conf</span><br><span class="line">root    10253    1  0 06:04 ?     00:00:46 &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod -f &#x2F;mongodb&#x2F;sharded_cluster&#x2F;myshardrs01_27218&#x2F;mongod.conf</span><br><span class="line">root    10312    1  0 06:04 ?     00:01:23 &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod -f &#x2F;mongodb&#x2F;sharded_cluster&#x2F;myshardrs02_27318&#x2F;mongod.conf</span><br><span class="line">root    10346    1  0 06:05 ?     00:01:23 &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod -f &#x2F;mongodb&#x2F;sharded_cluster&#x2F;myshardrs02_27418&#x2F;mongod.conf</span><br><span class="line">root    10380    1  0 06:05 ?     00:00:44 &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod -f &#x2F;mongodb&#x2F;sharded_cluster&#x2F;myshardrs02_27518&#x2F;mongod.conf</span><br><span class="line">root    10414    1  1 06:05 ?     00:01:36 &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod -f &#x2F;mongodb&#x2F;sharded_cluster&#x2F;myconfigrs_27019&#x2F;mongod.conf</span><br><span class="line">root    10453    1  1 06:05 ?     00:01:37 &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod -f &#x2F;mongodb&#x2F;sharded_cluster&#x2F;myconfigrs_27119&#x2F;mongod.conf</span><br><span class="line">root    10492    1  1 06:05 ?     00:01:38 &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod -f &#x2F;mongodb&#x2F;sharded_cluster&#x2F;myconfigrs_27219&#x2F;mongod.conf</span><br><span class="line">root    11392    1  0 06:15 ?     00:00:24 &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongos -f &#x2F;mongodb&#x2F;sharded_cluster&#x2F;mymongos_27017&#x2F;mongos.conf</span><br><span class="line">root    14829    1  0 07:15 ?     00:00:13 &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongos -f &#x2F;mongodb&#x2F;sharded_cluster&#x2F;mymongos_27117&#x2F;mongos.conf</span><br></pre></td></tr></table></figure>

<p>根据上述的进程编号，依次中断进程：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">kill -2 进程编号</span><br></pre></td></tr></table></figure>

<p>第二步：清除所有的节点的数据：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">rm -rf /mongodb/sharded_cluster/myconfigrs_27019/data/db/*.* \ &amp;</span><br><span class="line">rm -rf /mongodb/sharded_cluster/myconfigrs_27119/data/db/*.* \ &amp;</span><br><span class="line">rm -rf /mongodb/sharded_cluster/myconfigrs_27219/data/db/*.* \ &amp;</span><br><span class="line">rm -rf /mongodb/sharded_cluster/myshardrs01_27018/data/db/*.* \ &amp;</span><br><span class="line">rm -rf /mongodb/sharded_cluster/myshardrs01_27118/data/db/*.* \ &amp;</span><br><span class="line">rm -rf /mongodb/sharded_cluster/myshardrs01_27218/data/db/*.* \ &amp;</span><br><span class="line">rm -rf /mongodb/sharded_cluster/myshardrs02_27318/data/db/*.* \ &amp;</span><br><span class="line">rm -rf /mongodb/sharded_cluster/myshardrs02_27418/data/db/*.* \ &amp;</span><br><span class="line">rm -rf /mongodb/sharded_cluster/myshardrs02_27518/data/db/*.* \ &amp;</span><br><span class="line">rm -rf /mongodb/sharded_cluster/mymongos_27017/data/db/*.* \ &amp;</span><br><span class="line">rm -rf /mongodb/sharded_cluster/mymongos_27117/data/db/*.*</span><br></pre></td></tr></table></figure>

<p>第三步：查看或修改有问题的配置</p>
<p>第四步：依次启动所有节点，不包括路由节点：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs01_27018/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs01_27118/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs01_27218/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs02_27318/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs02_27418/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs02_27518/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myconfigrs_27019/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myconfigrs_27119/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myconfigrs_27219/mongod.conf</span><br></pre></td></tr></table></figure>

<p>第五步：对两个数据分片副本集和一个配置副本集进行初始化和相关配置</p>
<p>第六步：检查路由mongos的配置，并启动mongos</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/mymongos_27017/mongos.cfg</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/mymongos_27017/mongos.cfg</span><br></pre></td></tr></table></figure>

<p>第七步：mongo登录mongos，在其上进行相关操作。</p>
<h1 id="3-安全认证"><a href="#3-安全认证" class="headerlink" title="3.    安全认证"></a>3.    安全认证</h1><h2 id="3-1-MongoDB-的用户和角色权限简介"><a href="#3-1-MongoDB-的用户和角色权限简介" class="headerlink" title="3.1    MongoDB 的用户和角色权限简介"></a>3.1    MongoDB 的用户和角色权限简介</h2><p>默认情况下，MongoDB实例启动运行时是没有启用用户访问权限控制的，也就是说，在实例本机服务器上都可以随意连接到实例进行各种操作，MongoDB不会对连接客户端进行用户验证，这是非常危险的。</p>
<p>mongodb官网上说，为了能保障mongodb的安全可以做以下几个步骤：</p>
<ul>
<li>使用新的端口，默认的27017端口如果一旦知道了ip就能连接上，不太安全。</li>
<li>设置mongodb的网络环境，最好将mongodb部署到公司服务器内网，这样外网是访问不到的。公司内部访问使用vpn等。</li>
<li>开启安全认证。认证要同时设置服务器之间的内部认证方式，同时要设置客户端连接到集群的账号密码认证方式。</li>
</ul>
<p>为了强制开启用户访问控制(用户验证)，则需要在MongoDB实例启动时使用选项 – auth 或在指定启动配置文件中添加选项 auth=true 。</p>
<p>在开始之前需要了解一下概念</p>
<p>1）启用访问控制：</p>
<p>MongoDB使用的是基于角色的访问控制(Role-Based Access Control,RBAC)来管理用户对实例的访问。通过对用户授予一个或多个角色来控制用户访问数据库资源的权限和数据库操作的权限，在对用户分配角色之前，用户无法访问实例。</p>
<p>在实例启动时添加选项 – auth 或指定启动配置文件中添加选项 auth=true 。</p>
<p>2）角色：</p>
<p>在MongoDB中通过角色对用户授予相应数据库资源的操作权限，每个角色当中的权限可以显式指定，也可以通过继承其他角色的权限，或者两都都存在的权限。</p>
<p>3）权限：</p>
<p>权限由指定的数据库资源(resource)以及允许在指定资源上进行的操作(action)组成。</p>
<ul>
<li>资源(resource)包括：数据库、集合、部分集合和集群；</li>
<li>操作(action)包括：对资源进行的增、删、改、查(CRUD)操作。</li>
</ul>
<p>在角色定义时可以包含一个或多个已存在的角色，新创建的角色会继承包含的角色所有的权限。在同一个数据库中，新创建角色可以继承其他角色的权限，在 admin 数据库中创建的角色可以继承在其它任意数据库中角色的权限。</p>
<p>关于角色权限的查看，可以通过如下命令查询（了解）：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 查询所有角色权限(仅用户自定义角色)</span><br><span class="line">&gt; db.runCommand(&#123; rolesInfo: 1 &#125;)</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; 查询所有角色权限(包含内置角色)</span><br><span class="line">&gt; db.runCommand(&#123; rolesInfo: 1, showBuiltinRoles: true &#125;)</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; 查询当前数据库中的某角色的权限</span><br><span class="line">&gt; db.runCommand(&#123; rolesInfo: &quot;&lt;rolename&gt;&quot; &#125;)</span><br><span class="line">&#x2F;&#x2F; 查询其它数据库中指定的角色权限</span><br><span class="line">&gt; db.runCommand(&#123; rolesInfo: &#123; role: &quot;&lt;rolename&gt;&quot;, db: &quot;&lt;database&gt;&quot; &#125; &#125;</span><br><span class="line">&#x2F;&#x2F; 查询多个角色权限</span><br><span class="line">&gt; db.runCommand(</span><br><span class="line">    &#123;</span><br><span class="line">        rolesInfo: [</span><br><span class="line">            &quot;&lt;rolename&gt;&quot;,</span><br><span class="line">            &#123; role: &quot;&lt;rolename&gt;&quot;, db: &quot;&lt;database&gt;&quot; &#125;,</span><br><span class="line">            ...</span><br><span class="line">        ]  </span><br><span class="line">    &#125;</span><br><span class="line">)</span><br></pre></td></tr></table></figure>

<p>示例：</p>
<p>查看所有内置角色：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br></pre></td><td class="code"><pre><span class="line">&gt; db.runCommand(&#123; rolesInfo: 1, showBuiltinRoles: true &#125;)</span><br><span class="line">&#123;</span><br><span class="line">    &quot;roles&quot; : [</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;__queryableBackup&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;__system&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;backup&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;clusterAdmin&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;clusterManager&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;clusterMonitor&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;dbAdmin&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;dbAdminAnyDatabase&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;dbOwner&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;enableSharding&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;hostManager&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;read&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;readAnyDatabase&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;readWrite&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;readWriteAnyDatabase&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;restore&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;root&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;userAdmin&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;role&quot; : &quot;userAdminAnyDatabase&quot;,</span><br><span class="line">            &quot;db&quot; : &quot;admin&quot;,</span><br><span class="line">            &quot;isBuiltin&quot; : true,</span><br><span class="line">            &quot;roles&quot; : [ ],</span><br><span class="line">            &quot;inheritedRoles&quot; : [ ]</span><br><span class="line">        &#125;</span><br><span class="line">    ],</span><br><span class="line">    &quot;ok&quot; : 1</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>常用的内置角色：</p>
<ul>
<li>数据库用户角色： read、readWrite;</li>
<li>所有数据库用户角色： readAnyDatabase、readWriteAnyDatabase、userAdminAnyDatabase、dbAdminAnyDatabase</li>
<li>数据库管理角色： dbAdmin、dbOwner、userAdmin；</li>
<li>集群管理角色： clusterAdmin、clusterManager、clusterMonitor、hostManager；</li>
<li>备份恢复角色： backup、restore；</li>
<li>超级用户角色： root</li>
<li>内部角色： system</li>
</ul>
<p>角色说明：</p>
<table>
<thead>
<tr>
<th>角色</th>
<th>权限描述</th>
</tr>
</thead>
<tbody><tr>
<td>read</td>
<td>可以读取指定数据库中任何数据</td>
</tr>
<tr>
<td>readWrite</td>
<td>可以读写指定数据库中任何数据，包括创建、重命名、删除集合</td>
</tr>
<tr>
<td>readAnyDatabase</td>
<td>可以读取所有数据库中任何数据(除了数据库config和local之外)</td>
</tr>
<tr>
<td>readWriteAnyDatabase</td>
<td>可以读写所有数据库中任何数据(除了数据库config和local之外)</td>
</tr>
<tr>
<td>userAdminAnyDatabase</td>
<td>可以在指定数据库创建和修改用户(除了数据库config和local之外)</td>
</tr>
<tr>
<td>dbAdminAnyDatabase</td>
<td>可以读取任何数据库以及对数据库进行清理、修改、压缩、获取统计信息、执行检查等操作(除了数据库config和local之外)</td>
</tr>
<tr>
<td>dbAdmin</td>
<td>可以读取指定数据库以及对数据库进行清理、修改、压缩、获取统计信息、执行检查等操作</td>
</tr>
<tr>
<td>userAdmin</td>
<td>可以在指定数据库创建和修改用户</td>
</tr>
<tr>
<td>clusterAdmin</td>
<td>可以对整个集群或数据库系统进行管理操作</td>
</tr>
<tr>
<td>backup</td>
<td>备份MongoDB数据最小的权限</td>
</tr>
<tr>
<td>restore</td>
<td>从备份文件中还原恢复MongoDB数据(除了system.profile集合)的权限</td>
</tr>
<tr>
<td>root</td>
<td>超级账号，超级权限</td>
</tr>
</tbody></table>
<h2 id="3-2-单实例环境"><a href="#3-2-单实例环境" class="headerlink" title="3.2    单实例环境"></a>3.2    单实例环境</h2><p>目标：对单实例的MongoDB服务开启安全认证，这里的单实例指的是未开启副本集或分片的MongoDB实例。</p>
<h3 id="3-2-1-关闭已开启的服务"><a href="#3-2-1-关闭已开启的服务" class="headerlink" title="3.2.1    关闭已开启的服务"></a>3.2.1    关闭已开启的服务</h3><p>增加mongod的单实例的安全认证功能，可以在服务搭建的时候直接添加，也可以在之前搭建好的服务上添加。</p>
<p>本文使用之前搭建好的服务，因此，先停止之前的服务</p>
<p>停止服务的方式有两种：快速关闭和标准关闭，下面依次说明：</p>
<p>（1）快速关闭方法（快速，简单，数据可能会出错）</p>
<p>目标：通过系统的kill命令直接杀死进程：</p>
<p>杀完要检查一下，避免有的没有杀掉。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#通过进程编号关闭节点</span></span><br><span class="line"><span class="built_in">kill</span> -2 54410</span><br></pre></td></tr></table></figure>

<p>【补充】</p>
<p>如果一旦是因为数据损坏，则需要进行如下操作（了解）：</p>
<p>1）删除lock文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rm -f /mongodb/single/data/db/*.lock</span><br></pre></td></tr></table></figure>

<p>2 ）修复数据：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod --repair --dbpath=/mongodb/single/data/db</span><br></pre></td></tr></table></figure>

<p>（2）标准的关闭方法（数据不容易出错，但麻烦）：</p>
<p>目标：通过mongo客户端中的shutdownServer命令来关闭服务</p>
<p>主要的操作步骤参考如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">//客户端登录服务，注意，这里通过localhost登录，如果需要远程登录，必须先登录认证才行。</span><br><span class="line">mongo --port 27017</span><br><span class="line">//<span class="comment">#切换到admin库</span></span><br><span class="line">use admin</span><br><span class="line">//关闭服务</span><br><span class="line">db.shutdownServer()</span><br></pre></td></tr></table></figure>

<h3 id="3-2-2-添加用户和权限"><a href="#3-2-2-添加用户和权限" class="headerlink" title="3.2.2    添加用户和权限"></a>3.2.2    添加用户和权限</h3><p>（1）先按照普通无授权认证的配置，来配置服务端的配置文件 /mongodb/single/mongod.conf </p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">systemLog:</span></span><br><span class="line">    <span class="comment">#MongoDB发送所有日志输出的目标指定为文件</span></span><br><span class="line">    <span class="attr">destination:</span> <span class="string">file</span></span><br><span class="line">    <span class="comment">#mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径</span></span><br><span class="line">    <span class="attr">path:</span> <span class="string">"/mongodb/single/log/mongod.log"</span></span><br><span class="line">    <span class="comment">#当mongos或mongod实例重新启动时，mongos或mongod会将新条目附加到现有日志文件的末尾。</span></span><br><span class="line">    <span class="attr">logAppend:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">storage:</span></span><br><span class="line">    <span class="comment">#mongod实例存储其数据的目录。storage.dbPath设置仅适用于mongod。</span></span><br><span class="line">    <span class="attr">dbPath:</span> <span class="string">"/mongodb/single/data/db"</span></span><br><span class="line">    <span class="attr">journal:</span></span><br><span class="line">        <span class="comment">#启用或禁用持久性日志以确保数据文件保持有效和可恢复。</span></span><br><span class="line">        <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">processManagement:</span></span><br><span class="line">    <span class="comment">#启用在后台运行mongos或mongod进程的守护进程模式。</span></span><br><span class="line">    <span class="attr">fork:</span> <span class="literal">true</span></span><br><span class="line">    <span class="comment">#指定用于保存mongos或mongod进程的进程ID的文件位置，其中mongos或mongod将写入其PID</span></span><br><span class="line">    <span class="attr">pidFilePath:</span> <span class="string">"/mongodb/single/log/mongod.pid"</span></span><br><span class="line"><span class="attr">net:</span></span><br><span class="line">    <span class="comment">#服务实例绑定的IP</span></span><br><span class="line">    <span class="attr">bindIp:</span> <span class="string">localhost,192.168.0.2</span></span><br><span class="line">    <span class="comment">#绑定的端口</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">27017</span></span><br></pre></td></tr></table></figure>

<p>（2）按之前未开启认证的方式（不添加 – auth 参数）来启动MongoDB服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/single/mongod.conf</span><br></pre></td></tr></table></figure>

<p>提示：</p>
<p>在操作用户时，启动mongod服务时尽量不要开启授权。</p>
<p>（3）使用Mongo客户端登录</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongo --host 180.76.159.126 --port 27017</span><br></pre></td></tr></table></figure>

<p>（4）创建两个管理员用户，一个是系统的超级管理员 myroot ，一个是admin库的管理用户myadmin </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;切换到admin库</span><br><span class="line">&gt; use admin</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;创建系统超级用户 myroot,设置密码123456，设置角色root</span><br><span class="line">&#x2F;&#x2F;&gt; db.createUser(&#123;user:&quot;myroot&quot;,pwd:&quot;123456&quot;,roles:[ &#123; &quot;role&quot; : &quot;root&quot;, &quot;db&quot; : &quot;admin&quot; &#125; ]&#125;)</span><br><span class="line">&#x2F;&#x2F;或</span><br><span class="line">&gt; db.createUser(&#123;user:&quot;myroot&quot;,pwd:&quot;123456&quot;,roles:[&quot;root&quot;]&#125;)</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;创建专门用来管理admin库的账号myadmin，只用来作为用户权限的管理</span><br><span class="line">&gt; db.createUser(&#123;user:&quot;myadmin&quot;,pwd:&quot;123456&quot;,roles: [&#123;role:&quot;userAdminAnyDatabase&quot;,db:&quot;admin&quot;&#125;]&#125;)</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;查看已经创建了的用户的情况：</span><br><span class="line">&gt; db.system.users.find()</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;删除用户</span><br><span class="line">&gt; db.dropUser(&quot;myadmin&quot;)</span><br><span class="line">true</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;修改密码</span><br><span class="line">&gt; db.changeUserPassword(&quot;myroot&quot;, &quot;123456&quot;)</span><br></pre></td></tr></table></figure>

<p>提示：</p>
<ul>
<li>本案例创建了两个用户，分别对应超管和专门用来管理用户的角色，事实上，你只需要一个用户即可。如果你对安全要求很高，防止超管泄漏，则不要创建超管用户。</li>
<li>和其它数据库（MySQL）一样，权限的管理都差不多一样，也是将用户和权限信息保存到数据库对应的表中。Mongodb存储所有的用户信息在admin 数据库的集合system.users中，保存用户名、密码和数据库信息。</li>
<li>如果不指定数据库，则创建的指定的权限的用户在所有的数据库上有效，如 {role: “userAdminAnyDatabase”, db:””}</li>
</ul>
<p>（5）认证测试</p>
<p>测试添加的用户是否正确</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;切换到admin</span><br><span class="line">&gt; use admin</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;密码输错</span><br><span class="line">&gt; db.auth(&quot;myroot&quot;,&quot;12345&quot;)</span><br><span class="line">Error: Authentication failed.</span><br><span class="line">0</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;密码正确</span><br><span class="line">&gt; db.auth(&quot;myroot&quot;,&quot;123456&quot;)</span><br><span class="line">1</span><br></pre></td></tr></table></figure>

<p>（6）创建普通用户</p>
<p>创建普通用户可以在没有开启认证的时候添加，也可以在开启认证之后添加，但开启认证之后，必须使用有操作admin库的用户登录认证后才能操作。底层都是将用户信息保存在了admin数据库的集合system.users中</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;创建(切换)将来要操作的数据库articledb,</span><br><span class="line">&gt; use articledb</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;创建用户，拥有articledb数据库的读写权限readWrite，密码是123456</span><br><span class="line">&gt; db.createUser(&#123;user: &quot;bobo&quot;, pwd: &quot;123456&quot;, roles: [&#123; role: &quot;readWrite&quot;, db: &quot;articledb&quot; &#125;]&#125;)</span><br><span class="line">&#x2F;&#x2F;&gt; db.createUser(&#123;user: &quot;bobo&quot;, pwd: &quot;123456&quot;, roles: [&quot;readWrite&quot;]&#125;)</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;测试是否可用</span><br><span class="line">&gt; db.auth(&quot;bobo&quot;,&quot;123456&quot;)</span><br></pre></td></tr></table></figure>

<p>提示：</p>
<p>如果开启了认证后，登录的客户端的用户必须使用admin库的角色，如拥有root角色的myadmin用户，再通过myadmin用户去创建其他角色的用户</p>
<h3 id="3-2-3-服务端开启认证和客户端连接登录"><a href="#3-2-3-服务端开启认证和客户端连接登录" class="headerlink" title="3.2.3    服务端开启认证和客户端连接登录"></a>3.2.3    服务端开启认证和客户端连接登录</h3><h4 id="3-2-3-1-关闭已经启动的服务"><a href="#3-2-3-1-关闭已经启动的服务" class="headerlink" title="3.2.3.1    关闭已经启动的服务"></a>3.2.3.1    关闭已经启动的服务</h4><p>1）使用linux命令杀死进程：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost single]<span class="comment"># ps -ef |grep mongo</span></span><br><span class="line">root    23482    1  0 08:08 ?     00:00:55 /usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/single/mongod.conf</span><br><span class="line">[root@bobohost single]<span class="comment"># kill -2 23482</span></span><br></pre></td></tr></table></figure>

<p>2 ）在mongo客户端中使用shutdownServer命令来关闭</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">&gt; db.shutdownServer()</span><br><span class="line">shutdown command only works with the admin database; try &#39;use admin&#39;</span><br><span class="line">&gt; use admin</span><br><span class="line">switched to db admin</span><br><span class="line">&gt; db.shutdownServer()</span><br><span class="line">2019-08-14T11:20:16.450+0800 E QUERY  [js] Error: shutdownServer failed: &#123;</span><br><span class="line">    &quot;ok&quot; : 0,</span><br><span class="line">    &quot;errmsg&quot; : &quot;shutdown must run from localhost when running db without auth&quot;,</span><br><span class="line">    &quot;code&quot; : 13,</span><br><span class="line">    &quot;codeName&quot; : &quot;Unauthorized&quot;</span><br><span class="line">    &#125; :</span><br><span class="line">_getErrorWithCode@src&#x2F;mongo&#x2F;shell&#x2F;utils.js:25:13</span><br><span class="line">DB.prototype.shutdownServer@src&#x2F;mongo&#x2F;shell&#x2F;db.js:453:1</span><br><span class="line">@(shell):1:1</span><br></pre></td></tr></table></figure>

<p>需要几个条件：</p>
<ul>
<li>必须是在 admin库下执行该关闭服务命令。</li>
<li>如果没有开启认证，必须是从 localhost登陆的，才能执行关闭服务命令。</li>
<li>非 localhost的、通过远程登录的，必须有登录且必须登录用户有对admin操作权限才可以。</li>
</ul>
<h4 id="3-2-3-2-以开启认证的方式启动服务"><a href="#3-2-3-2-以开启认证的方式启动服务" class="headerlink" title="3.2.3.2    以开启认证的方式启动服务"></a>3.2.3.2    以开启认证的方式启动服务</h4><p>有两种方式开启权限认证启动服务：一种是参数方式，一种是配置文件方式</p>
<p>1）参数方式</p>
<p>在启动时指定参数 – auth ，如：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/single/mongod.conf --auth</span><br></pre></td></tr></table></figure>

<p>2）配置文件方式</p>
<p>在mongod.conf配置文件中加入：vim /mongodb/single/mongod.conf</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">security:</span></span><br><span class="line">    <span class="comment">#开启授权认证</span></span><br><span class="line">    <span class="attr">authorization:</span> <span class="string">enabled</span></span><br></pre></td></tr></table></figure>

<p>启动时可不加 – auth 参数：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/single/mongod.conf</span><br></pre></td></tr></table></figure>

<h4 id="3-2-3-3-开启了认证的情况下的客户端登录"><a href="#3-2-3-3-开启了认证的情况下的客户端登录" class="headerlink" title="3.2.3.3    开启了认证的情况下的客户端登录"></a>3.2.3.3    开启了认证的情况下的客户端登录</h4><p>有两种认证方式，一种是先登录，在mongo shell中认证；一种是登录时直接认证</p>
<p>1）先连接再认证</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost bin]# &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongo --host 180.76.159.126 --port 27017</span><br><span class="line">MongoDB shell version v4.0.10</span><br><span class="line">connecting to: mongodb:&#x2F;&#x2F;180.76.159.126:27017&#x2F;?gssapiServiceName&#x3D;mongodb</span><br><span class="line">Implicit session: session &#123; &quot;id&quot; : UUID(&quot;53fef661-35d6-4d29-b07c-020291d62e1a&quot;)&#125;</span><br><span class="line">MongoDB server version: 4.0.10</span><br><span class="line">&gt;</span><br></pre></td></tr></table></figure>

<p>提示：</p>
<p>开启认证后再登录，发现打印的日志比较少了。</p>
<p>相关操作需要认证才可以：</p>
<p>查询admin库中的system.users集合的用户：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&gt; use admin</span><br><span class="line">switched to db admin</span><br><span class="line">&gt; db.system.users.find()</span><br><span class="line">Error: error: &#123;</span><br><span class="line">    &quot;ok&quot; : 0,</span><br><span class="line">    &quot;errmsg&quot; : &quot;command find requires authentication&quot;,</span><br><span class="line">    &quot;code&quot; : 13,</span><br><span class="line">    &quot;codeName&quot; : &quot;Unauthorized&quot;</span><br><span class="line">&#125;</span><br><span class="line">&gt; db.auth(&quot;myroot&quot;,&quot;123456&quot;)</span><br><span class="line">1</span><br><span class="line">&gt; db.system.users.find()</span><br></pre></td></tr></table></figure>

<p>查询articledb库中的comment集合的内容：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">&gt; use articledb</span><br><span class="line">switched to db articledb</span><br><span class="line">&gt; db.comment.find()</span><br><span class="line">Error: error: &#123;</span><br><span class="line">    &quot;ok&quot; : 0,</span><br><span class="line">    &quot;errmsg&quot; : &quot;not authorized on articledb to execute command &#123; find: \&quot;comment\&quot;, filter: &#123;&#125;, lsid: &#123; id: UUID(\&quot;53fef661-35d6-4d29-b07c-020291d62e1a\&quot;) &#125;, $db: \&quot;articledb\&quot; &#125;&quot;,</span><br><span class="line">    &quot;code&quot; : 13,</span><br><span class="line">    &quot;codeName&quot; : &quot;Unauthorized&quot;</span><br><span class="line">&#125;</span><br><span class="line">&gt; db.auth(&quot;bobo&quot;,&quot;123456&quot;)</span><br><span class="line">1</span><br><span class="line">&gt; db.comment.find()</span><br><span class="line">Error: error: &#123;</span><br><span class="line">    &quot;ok&quot; : 0,</span><br><span class="line">    &quot;errmsg&quot; : &quot;too many users are authenticated&quot;,</span><br><span class="line">    &quot;code&quot; : 13,</span><br><span class="line">    &quot;codeName&quot; : &quot;Unauthorized&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>提示：</p>
<p>这里可能出现错误，说是太多的用户正在认证了。因为我们确实连续登录了两个用户了。</p>
<p>解决方案：退出shell，重新进来登录认证</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">&gt; exit</span><br><span class="line">bye</span><br><span class="line">[root@bobohost bin]# .&#x2F;mongo --host 180.76.159.126 --port 27017</span><br><span class="line">MongoDB shell version v4.0.10</span><br><span class="line">connecting to: mongodb:&#x2F;&#x2F;180.76.159.126:27017&#x2F;?gssapiServiceName&#x3D;mongodb</span><br><span class="line">Implicit session: session &#123; &quot;id&quot; : UUID(&quot;329c1897-566d-4231-bcb3-b2acda301863&quot;)</span><br><span class="line">&#125;</span><br><span class="line">MongoDB server version: 4.0.10</span><br><span class="line">&gt; db.auth(&quot;bobo&quot;,&quot;123456&quot;)</span><br><span class="line">Error: Authentication failed.</span><br><span class="line">0</span><br><span class="line">&gt; use articledb</span><br><span class="line">switched to db articledb</span><br><span class="line">&gt; db.auth(&quot;bobo&quot;,&quot;123456&quot;)</span><br><span class="line">1</span><br><span class="line">&gt; db.comment.find()</span><br></pre></td></tr></table></figure>

<p>2）连接时直接认证</p>
<p>对admin数据库进行登录认证和相关操作：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost ~]# &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongo --host 180.76.159.126 --port 27017 --authenticationDatabase admin -u myroot -p 123456</span><br><span class="line">MongoDB shell version v4.0.10</span><br><span class="line">connecting to: mongodb:&#x2F;&#x2F;180.76.159.126:27017&#x2F;?</span><br><span class="line">authSource&#x3D;admin&amp;gssapiServiceName&#x3D;mongodb</span><br><span class="line">Implicit session: session &#123; &quot;id&quot; : UUID(&quot;f959b8d6-6994-44bc-9d35-09fc7cd00ba6&quot;)</span><br><span class="line">&#125;</span><br><span class="line">MongoDB server version: 4.0.10</span><br><span class="line">Server has startup warnings:</span><br><span class="line">2019-09-10T15:23:40.102+0800 I CONTROL [initandlisten] ** WARNING: You are</span><br><span class="line">running this process as the root user, which is not recommended.</span><br><span class="line">2019-09-10T15:23:40.102+0800 I CONTROL [initandlisten]</span><br><span class="line">2019-09-10T15:23:40.102+0800 I CONTROL [initandlisten]</span><br><span class="line">2019-09-10T15:23:40.102+0800 I CONTROL [initandlisten] ** WARNING:</span><br><span class="line">&#x2F;sys&#x2F;kernel&#x2F;mm&#x2F;transparent_hugepage&#x2F;enabled is &#39;always&#39;.</span><br><span class="line">2019-09-10T15:23:40.102+0800 I CONTROL [initandlisten] **    We suggest</span><br><span class="line">setting it to &#39;never&#39;</span><br><span class="line">2019-09-10T15:23:40.102+0800 I CONTROL [initandlisten]</span><br><span class="line">2019-09-10T15:23:40.102+0800 I CONTROL [initandlisten] ** WARNING:</span><br><span class="line">&#x2F;sys&#x2F;kernel&#x2F;mm&#x2F;transparent_hugepage&#x2F;defrag is &#39;always&#39;.</span><br><span class="line">2019-09-10T15:23:40.102+0800 I CONTROL [initandlisten] **    We suggest</span><br><span class="line">setting it to &#39;never&#39;</span><br><span class="line">2019-09-10T15:23:40.102+0800 I CONTROL [initandlisten]</span><br><span class="line">&gt; show dbs;</span><br><span class="line">admin    0.000GB</span><br><span class="line">articledb  0.000GB</span><br><span class="line">config   0.000GB</span><br><span class="line">local    0.000GB</span><br></pre></td></tr></table></figure>

<p>对articledb数据库进行登录认证和相关操作：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost bin]# &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongo --host 180.76.159.126 --port 27017 --authenticationDatabase articledb -u bobo -p 123456</span><br><span class="line">MongoDB shell version v4.0.10</span><br><span class="line">connecting to: mongodb:&#x2F;&#x2F;180.76.159.126:27017&#x2F;?</span><br><span class="line">authSource&#x3D;articledb&amp;gssapiServiceName&#x3D;mongodb</span><br><span class="line">Implicit session: session &#123; &quot;id&quot; : UUID(&quot;e5d4148f-373b-45b8-9cff-a927ce617100&quot;)</span><br><span class="line">&#125;</span><br><span class="line">MongoDB server version: 4.0.10</span><br><span class="line">&gt; use articledb</span><br><span class="line">switched to db articledb</span><br><span class="line">&gt; db.comment.find()</span><br></pre></td></tr></table></figure>

<p>提示：</p>
<ul>
<li><code>-u</code> ：用户名</li>
<li><code>-p</code> ：密码</li>
<li><code>-- authenticationDatabase</code> ：指定连接到哪个库。当登录是指定用户名密码时，必须指定对应的数据库！</li>
</ul>
<h3 id="3-2-4-SpringDataMongoDB连接认证"><a href="#3-2-4-SpringDataMongoDB连接认证" class="headerlink" title="3.2.4    SpringDataMongoDB连接认证"></a>3.2.4    SpringDataMongoDB连接认证</h3><p>使用用户名和密码连接到 MongoDB 服务器，你必须使用<code>&#39;username:password@hostname/dbname&#39;</code> 格式，’username’为用户名，’password’ 为密码。</p>
<p>目标：使用用户bobo使用密码 123456 连接到MongoDB 服务上。</p>
<p>application.yml：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">    <span class="comment">#数据源配置</span></span><br><span class="line">    <span class="attr">data:</span></span><br><span class="line">        <span class="attr">mongodb:</span></span><br><span class="line">            <span class="comment"># 主机地址</span></span><br><span class="line">            <span class="comment">#   host: 180.76.159.126</span></span><br><span class="line">            <span class="comment"># 数据库</span></span><br><span class="line">            <span class="comment">#   database: articledb</span></span><br><span class="line">            <span class="comment"># 默认端口是27017</span></span><br><span class="line">            <span class="comment">#   port: 27017</span></span><br><span class="line">            <span class="comment">#帐号</span></span><br><span class="line">            <span class="comment">#   username: bobo</span></span><br><span class="line">            <span class="comment">#密码</span></span><br><span class="line">            <span class="comment">#   password: 123456</span></span><br><span class="line">            <span class="comment">#单机有认证的情况下，也使用字符串连接</span></span><br><span class="line">            <span class="attr">uri:</span> <span class="string">mongodb://bobo:123456@180.76.159.126:27017/articledb</span></span><br></pre></td></tr></table></figure>

<h2 id="3-3-副本集环境"><a href="#3-3-副本集环境" class="headerlink" title="3.3    副本集环境"></a>3.3    副本集环境</h2><h3 id="3-3-1-前言"><a href="#3-3-1-前言" class="headerlink" title="3.3.1    前言"></a>3.3.1    前言</h3><p>对于搭建好的mongodb副本集，为了安全，启动安全认证，使用账号密码登录。</p>
<p>副本集环境使用之前搭建好的，架构如下：</p>
<p><img src="https://img-blog.csdnimg.cn/20200918165235785.png" alt="image-20200918145643639"></p>
<p>对副本集执行访问控制需要配置两个方面 :</p>
<ul>
<li>副本集和共享集群的各个节点成员之间使用内部身份验证，可以使用密钥文件或x.509证书。密钥文件比较简单，本文使用密钥文件，官方推荐如果是测试环境可以使用密钥文件，但是正式环境，官方推荐x.509证书。原理就是，集群中每一个实例彼此连接的时候都检验彼此使用的证书的内容是否相同。只有证书相同的实例彼此才可以访问</li>
<li>使用客户端连接到mongodb集群时，开启访问授权。对于集群外部的访问。如通过可视化客户端，或者通过代码连接的时候，需要开启授权。</li>
</ul>
<p>在keyfile身份验证中，副本集中的每个mongod实例都使用keyfile的内容作为共享密码，只有具有正确密钥文件的mongod或者mongos实例可以连接到副本集。密钥文件的内容必须在6到1024个字符之间，并且在unix/linux系统中文件所有者必须有对文件至少有读的权限。</p>
<h3 id="3-3-2-关闭已开启的副本集服务"><a href="#3-3-2-关闭已开启的副本集服务" class="headerlink" title="3.3.2    关闭已开启的副本集服务"></a>3.3.2    关闭已开启的副本集服务</h3><p>增加副本集的安全认证和服务鉴权功能，可以在副本集搭建的时候直接添加，也可以在之前搭建好的副本集服务上添加。</p>
<p>本文使用之前搭建好的副本集服务，因此，先停止之前的集群服务</p>
<p>停止服务的方式有两种：快速关闭和标准关闭，下面依次说明：</p>
<p>（1）快速关闭方法（快速，简单，数据可能会出错）</p>
<p>目标：通过系统的kill命令直接杀死进程：</p>
<p>依次杀死仲裁者、副本节点、主节点，直到所有成员都离线。建议主节点最后kill，以避免潜在的回滚。杀完要检查一下，避免有的没有杀掉。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#通过进程编号关闭节点</span></span><br><span class="line"><span class="built_in">kill</span> -2 54410</span><br></pre></td></tr></table></figure>

<p>【补充】</p>
<p>如果一旦是因为数据损坏，则需要进行如下操作（了解）：</p>
<p>1）删除lock文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">rm -f /mongodb/replica_sets/myrs_27017/data/db/*.lock \</span><br><span class="line">/mongodb/replica_sets/myrs_27018/data/db/*.lock \</span><br><span class="line">/mongodb/replica_sets/myrs_27019/data/db/mongod.lock \</span><br></pre></td></tr></table></figure>

<p>2 ）依次修复数据：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod --repair --dbpath&#x3D;&#x2F;mongodb&#x2F;replica_sets&#x2F;myrs_27017&#x2F;data&#x2F;db</span><br><span class="line">&#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod --repair --dbpath&#x3D;&#x2F;mongodb&#x2F;replica_sets&#x2F;myrs_27018&#x2F;data&#x2F;db</span><br><span class="line">&#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod --repair --dbpath&#x3D;&#x2F;mongodb&#x2F;replica_sets&#x2F;myrs_27019&#x2F;data&#x2F;db</span><br></pre></td></tr></table></figure>

<p>（2）标准的关闭方法（数据不容易出错，但麻烦）</p>
<p>目标：通过mongo客户端中的shutdownServer命令来依次关闭各个服务</p>
<p>关闭副本集中的服务，建议依次关闭仲裁节点、副本节点、主节点。主要的操作步骤参考如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;客户端登录服务，注意，这里通过localhost登录，如果需要远程登录，必须先登录认证才行。</span><br><span class="line">mongo --port 27017</span><br><span class="line">&#x2F;&#x2F;告知副本集说本机要下线</span><br><span class="line">rs.stepDown()</span><br><span class="line">&#x2F;&#x2F;#切换到admin库</span><br><span class="line">use admin</span><br><span class="line">&#x2F;&#x2F;关闭服务</span><br><span class="line">db.shutdownServer()</span><br></pre></td></tr></table></figure>

<h3 id="3-3-3-通过主节点添加一个管理员帐号"><a href="#3-3-3-通过主节点添加一个管理员帐号" class="headerlink" title="3.3.3    通过主节点添加一个管理员帐号"></a>3.3.3    通过主节点添加一个管理员帐号</h3><p>只需要在主节点上添加用户，副本集会自动同步。</p>
<p>开启认证之前，创建超管用户：myroot，密码：123456</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">myrs:PRIMARY&gt; use admin</span><br><span class="line">switched to db admin</span><br><span class="line">myrs:PRIMARY&gt; db.createUser(&#123;user:&quot;myroot&quot;,pwd:&quot;123456&quot;,roles:[&quot;root&quot;]&#125;)</span><br><span class="line">Successfully added user: &#123; &quot;user&quot; : &quot;myroot&quot;, &quot;roles&quot; : [ &quot;root&quot; ] &#125;</span><br></pre></td></tr></table></figure>

<p>该步骤也可以在开启认证之后，但需要通过localhost登录才允许添加用户，用户数据也会自动同步到副本集。</p>
<p>后续再创建其他用户，都可以使用该超管用户创建。</p>
<h3 id="3-3-4-创建副本集认证的key文件"><a href="#3-3-4-创建副本集认证的key文件" class="headerlink" title="3.3.4    创建副本集认证的key文件"></a>3.3.4    创建副本集认证的key文件</h3><p>第一步：生成一个key文件到当前文件夹中。</p>
<p>可以使用任何方法生成密钥文件。例如，以下操作使用openssl生成密码文件，然后使用chmod来更改文件权限，仅为文件所有者提供读取权限</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost ~]# openssl rand -base64 90 -out .&#x2F;mongo.keyfile</span><br><span class="line">[root@bobohost ~]# chmod 400 .&#x2F;mongo.keyfile</span><br><span class="line">[root@bobohost ~]# ll mongo.keyfile</span><br><span class="line">-r--------. 1 root root 122 8月  14 14:23 mongo.keyfile</span><br></pre></td></tr></table></figure>

<p>提示：</p>
<p>所有副本集节点都必须要用同一份keyfile，一般是在一台机器上生成，然后拷贝到其他机器上，且必须有读的权限，否则将来会报错： permissions on /mongodb/replica_sets/myrs_27017/mongo.keyfile are too open</p>
<p>一定要保证密钥文件一致，文件位置随便。但是为了方便查找，建议每台机器都放到一个固定的位置，都放到和配置文件一起的目录中。</p>
<p>这里将该文件分别拷贝到多个目录中：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost ~]<span class="comment"># cp mongo.keyfile /mongodb/replica_sets/myrs_27017</span></span><br><span class="line">[root@bobohost ~]<span class="comment"># cp mongo.keyfile /mongodb/replica_sets/myrs_27018</span></span><br><span class="line">[root@bobohost ~]<span class="comment"># cp mongo.keyfile /mongodb/replica_sets/myrs_27019</span></span><br></pre></td></tr></table></figure>

<h3 id="3-3-5-修改配置文件指定keyfile"><a href="#3-3-5-修改配置文件指定keyfile" class="headerlink" title="3.3.5    修改配置文件指定keyfile"></a>3.3.5    修改配置文件指定keyfile</h3><p>分别编辑几个服务的mongod.conf文件，添加相关内容</p>
<p>/mongodb/replica_sets/myrs_27017/mongod.conf</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">security:</span></span><br><span class="line">    <span class="comment">#KeyFile鉴权文件</span></span><br><span class="line">    <span class="attr">keyFile:</span> <span class="string">/mongodb/replica_sets/myrs_27017/mongo.keyfile</span></span><br><span class="line">    <span class="comment">#开启认证方式运行</span></span><br><span class="line">    <span class="attr">authorization:</span> <span class="string">enabled</span></span><br></pre></td></tr></table></figure>

<p>/mongodb/replica_sets/myrs_27018/mongod.conf</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">security:</span></span><br><span class="line">    <span class="comment">#KeyFile鉴权文件</span></span><br><span class="line">    <span class="attr">keyFile:</span> <span class="string">/mongodb/replica_sets/myrs_27018/mongo.keyfile</span></span><br><span class="line">    <span class="comment">#开启认证方式运行</span></span><br><span class="line">    <span class="attr">authorization:</span> <span class="string">enabled</span></span><br></pre></td></tr></table></figure>

<p>/mongodb/replica_sets/myrs_27019/mongod.conf</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">security:</span></span><br><span class="line">    <span class="comment">#KeyFile鉴权文件</span></span><br><span class="line">    <span class="attr">keyFile:</span> <span class="string">/mongodb/replica_sets/myrs_27019/mongo.keyfile</span></span><br><span class="line">    <span class="comment">#开启认证方式运行</span></span><br><span class="line">    <span class="attr">authorization:</span> <span class="string">enabled</span></span><br></pre></td></tr></table></figure>

<h3 id="3-3-6-重新启动副本集"><a href="#3-3-6-重新启动副本集" class="headerlink" title="3.3.6    重新启动副本集"></a>3.3.6    重新启动副本集</h3><p>如果副本集是开启状态，则先分别关闭关闭复本集中的每个mongod，从次节点开始。直到副本集的所有成员都离线，包括任何仲裁者。主节点必须是最后一个成员关闭以避免潜在的回滚。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#通过进程编号关闭三个节点</span></span><br><span class="line"><span class="built_in">kill</span> -2 54410 54361 54257</span><br></pre></td></tr></table></figure>

<p>分别启动副本集节点：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/replica_sets/myrs_27017/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/replica_sets/myrs_27018/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/replica_sets/myrs_27019/mongod.conf</span><br></pre></td></tr></table></figure>

<p>查看进程情况：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost replica_sets]<span class="comment"># ps -ef |grep mongod</span></span><br><span class="line">root    62425    1  5 14:43 ?     00:00:01 /usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/replica_sets/myrs_27017/mongod.conf</span><br><span class="line">root    62495    1  7 14:43 ?     00:00:01 /usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/replica_sets/myrs_27018/mongod.conf</span><br><span class="line">root    62567    1 11 14:43 ?     00:00:01 /usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/replica_sets/myrs_27019/mongod.conf</span><br></pre></td></tr></table></figure>

<h3 id="3-3-7-在主节点上添加普通账号"><a href="#3-3-7-在主节点上添加普通账号" class="headerlink" title="3.3.7    在主节点上添加普通账号"></a>3.3.7    在主节点上添加普通账号</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">#先用管理员账号登录</span><br><span class="line">#切换到admin库</span><br><span class="line">use admin</span><br><span class="line">#管理员账号认证</span><br><span class="line">db.auth(&quot;myroot&quot;,&quot;123456&quot;)</span><br><span class="line">#切换到要认证的库</span><br><span class="line">use articledb</span><br><span class="line">#添加普通用户</span><br><span class="line">db.createUser(&#123;user: &quot;bobo&quot;, pwd: &quot;123456&quot;, roles: [&quot;readWrite&quot;]&#125;)</span><br></pre></td></tr></table></figure>

<p>重新连接，使用普通用户 bobo重新登录，查看数据。</p>
<h3 id="3-3-8-SpringDataMongoDB连接副本集"><a href="#3-3-8-SpringDataMongoDB连接副本集" class="headerlink" title="3.3.8    SpringDataMongoDB连接副本集"></a>3.3.8    SpringDataMongoDB连接副本集</h3><p>使用用户名和密码连接到 MongoDB 服务器，你必须使用<code>&#39;username:password@hostname/dbname&#39;</code> 格式，’username’为用户名，’password’ 为密码。</p>
<p>目标：使用用户bobo使用密码 123456 连接到MongoDB 服务上。</p>
<p>application.yml：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">    <span class="comment">#数据源配置</span></span><br><span class="line">    <span class="attr">data:</span></span><br><span class="line">        <span class="attr">mongodb:</span></span><br><span class="line">            <span class="comment">#副本集有认证的情况下，字符串连接</span></span><br><span class="line">            <span class="attr">uri:</span> <span class="string">mongodb://bobo:123456@180.76.159.126:27017,180.76.159.126:27018,180.76.159.126:27019/articledb?connect=replicaSet&amp;slaveOk=true&amp;replicaSet=myrs</span></span><br></pre></td></tr></table></figure>

<h2 id="3-4-分片集群环境-扩展"><a href="#3-4-分片集群环境-扩展" class="headerlink" title="3.4    分片集群环境(扩展)"></a>3.4    分片集群环境(扩展)</h2><h3 id="3-4-1-关闭已开启的集群服务"><a href="#3-4-1-关闭已开启的集群服务" class="headerlink" title="3.4.1    关闭已开启的集群服务"></a>3.4.1    关闭已开启的集群服务</h3><p>分片集群环境下的安全认证和副本集环境下基本上一样。</p>
<p>但分片集群的服务器环境和架构较为复杂，建议在搭建分片集群的时候，直接加入安全认证和服务器间的鉴权，如果之前有数据，可先将之前的数据备份出来，再还原回去。</p>
<p>本文使用之前搭建好的集群服务，因此，先停止之前的集群服务</p>
<p>停止服务的方式有两种：快速关闭和标准关闭，下面依次说明：</p>
<p>（1）快速关闭方法（快速，简单，数据可能会出错）</p>
<p>目标：通过系统的kill命令直接杀死进程：</p>
<p>依次杀死 mongos路由、配置副本集服务，分片副本集服务，从次节点开始。直到所有成员都离线。副本集杀的时候，建议先杀仲裁者，再杀副本节点，最后是主节点，以避免潜在的回滚。杀完要检查一下，避免有的没有杀掉。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#通过进程编号关闭节点</span></span><br><span class="line"><span class="built_in">kill</span> -2 54410</span><br></pre></td></tr></table></figure>

<p>【补充】</p>
<p>如果一旦是因为数据损坏，则需要进行如下操作（了解）：</p>
<p>1）删除lock文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">rm -f /mongodb/sharded_cluster/myshardrs01_27018/data/db/*.lock \</span><br><span class="line">/mongodb/sharded_cluster/myshardrs01_27118/data/db/*.lock \</span><br><span class="line">/mongodb/sharded_cluster/myshardrs01_27218/data/db/mongod.lock \</span><br><span class="line">/mongodb/sharded_cluster/myshardrs02_27318/data/db/mongod.lock \</span><br><span class="line">/mongodb/sharded_cluster/myshardrs02_27418/data/db/mongod.lock \</span><br><span class="line">/mongodb/sharded_cluster/myshardrs02_27518/data/db/mongod.lock \</span><br><span class="line">/mongodb/sharded_cluster/myconfigrs_27019/data/db/mongod.lock \</span><br><span class="line">/mongodb/sharded_cluster/myconfigrs_27119/data/db/mongod.lock \</span><br><span class="line">/mongodb/sharded_cluster/myconfigrs_27219/data/db/mongod.lock</span><br></pre></td></tr></table></figure>

<p>2 ）依次修复数据：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod --repair --</span><br><span class="line">dbpath&#x3D;&#x2F;mongodb&#x2F;sharded_cluster&#x2F;myshardrs01_27018&#x2F;data&#x2F;db</span><br><span class="line">&#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod --repair --</span><br><span class="line">dbpath&#x3D;&#x2F;mongodb&#x2F;sharded_cluster&#x2F;myshardrs01_27118&#x2F;data&#x2F;db</span><br><span class="line">&#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod --repair --</span><br><span class="line">dbpath&#x3D;&#x2F;mongodb&#x2F;sharded_cluster&#x2F;myshardrs01_27218&#x2F;data&#x2F;db</span><br><span class="line">&#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod --repair --</span><br><span class="line">dbpath&#x3D;&#x2F;mongodb&#x2F;sharded_cluster&#x2F;myshardrs02_27318&#x2F;data&#x2F;db</span><br><span class="line">&#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod --repair --</span><br><span class="line">dbpath&#x3D;&#x2F;mongodb&#x2F;sharded_cluster&#x2F;myshardrs02_27418&#x2F;data&#x2F;db</span><br><span class="line">&#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod --repair --</span><br><span class="line">dbpath&#x3D;&#x2F;mongodb&#x2F;sharded_cluster&#x2F;myshardrs02_27518&#x2F;data&#x2F;db</span><br><span class="line">&#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod --repair --</span><br><span class="line">dbpath&#x3D;&#x2F;mongodb&#x2F;sharded_cluster&#x2F;myconfigrs_27019&#x2F;data&#x2F;db</span><br><span class="line">&#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod --repair --</span><br><span class="line">dbpath&#x3D;&#x2F;mongodb&#x2F;sharded_cluster&#x2F;myconfigrs_27119&#x2F;data&#x2F;db</span><br><span class="line">&#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod --repair --</span><br><span class="line">dbpath&#x3D;&#x2F;mongodb&#x2F;sharded_cluster&#x2F;myconfigrs_27219&#x2F;data&#x2F;db</span><br><span class="line">&#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod --repair --</span><br><span class="line">dbpath&#x3D;&#x2F;mongodb&#x2F;sharded_cluster&#x2F;mymongos_27017&#x2F;data&#x2F;db</span><br><span class="line">&#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongod --repair --</span><br><span class="line">dbpath&#x3D;&#x2F;mongodb&#x2F;sharded_cluster&#x2F;mymongos_27117&#x2F;data&#x2F;db</span><br></pre></td></tr></table></figure>

<p>（2）标准的关闭方法（数据不容易出错，但麻烦）：</p>
<p>目标：通过mongo客户端中的shutdownServer命令来依次关闭各个服务</p>
<p>关闭分片服务器副本集中的服务，建议依次关闭仲裁节点、副本节点、主节点。主要的操作步骤参考如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;客户端登录服务，注意，这里通过localhost登录，如果需要远程登录，必须先登录认证才行。</span><br><span class="line">mongo --port 27018</span><br><span class="line">&#x2F;&#x2F;告知副本集说本机要下线</span><br><span class="line">rs.stepDown()</span><br><span class="line">&#x2F;&#x2F;#切换到admin库</span><br><span class="line">use admin</span><br><span class="line">&#x2F;&#x2F;关闭服务</span><br><span class="line">db.shutdownServer()</span><br></pre></td></tr></table></figure>

<p>关闭配置服务器副本集的服务，建议依次关闭副本节点、主节点。主要的操作步骤参考如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;客户端登录服务，注意，这里通过localhost登录，如果需要远程登录，必须先登录认证才行。</span><br><span class="line">mongo --port 27019</span><br><span class="line">&#x2F;&#x2F;告知副本集说本机要下线</span><br><span class="line">rs.stepDown()</span><br><span class="line">&#x2F;&#x2F;#切换到admin库</span><br><span class="line">use admin</span><br><span class="line">&#x2F;&#x2F;关闭服务</span><br><span class="line">db.shutdownServer()</span><br></pre></td></tr></table></figure>

<p>关闭路由服务器的服务，建议依次关闭两个路由节点。主要的操作步骤参考如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;客户端登录服务，注意，这里通过localhost登录，如果需要远程登录，必须先登录认证才行。</span><br><span class="line">mongo --port 27017</span><br><span class="line">&#x2F;&#x2F;告知副本集说本机要下线</span><br><span class="line">rs.stepDown()</span><br><span class="line">&#x2F;&#x2F;#切换到admin库</span><br><span class="line">use admin</span><br><span class="line">&#x2F;&#x2F;关闭服务</span><br><span class="line">db.shutdownServer()</span><br></pre></td></tr></table></figure>

<h3 id="3-4-2-创建副本集认证的key文件"><a href="#3-4-2-创建副本集认证的key文件" class="headerlink" title="3.4.2    创建副本集认证的key文件"></a>3.4.2    创建副本集认证的key文件</h3><p>第一步：生成一个key文件到当前文件夹中。</p>
<p>可以使用任何方法生成密钥文件。例如，以下操作使用openssl生成密码文件，然后使用chmod来更改文件权限，仅为文件所有者提供读取权限</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost ~]<span class="comment"># openssl rand -base64 90 -out ./mongo.keyfile</span></span><br><span class="line">[root@bobohost ~]<span class="comment"># chmod 400 ./mongo.keyfile</span></span><br><span class="line">[root@bobohost ~]<span class="comment"># ll mongo.keyfile</span></span><br><span class="line">-r--------. 1 root root 122 8月  14 14:23 mongo.keyfile</span><br></pre></td></tr></table></figure>

<p>提示：</p>
<p>所有副本集节点都必须要用同一份keyfile，一般是在一台机器上生成，然后拷贝到其他机器上，且必须<br>有读的权限，否则将来会报错： permissions on /mongodb/replica_sets/myrs_27017/mongo.keyfile are too open</p>
<p>一定要保证密钥文件一致，文件位置随便。但是为了方便查找，建议每台机器都放到一个固定的位置，都放到和配置文件一起的目录中。</p>
<p>这里将该文件分别拷贝到多个目录中：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">echo</span> <span class="string">'/mongodb/sharded_cluster/myshardrs01_27018/mongo.keyfile</span></span><br><span class="line"><span class="string">/mongodb/sharded_cluster/myshardrs01_27118/mongo.keyfile</span></span><br><span class="line"><span class="string">/mongodb/sharded_cluster/myshardrs01_27218/mongo.keyfile</span></span><br><span class="line"><span class="string">/mongodb/sharded_cluster/myshardrs02_27318/mongo.keyfile</span></span><br><span class="line"><span class="string">/mongodb/sharded_cluster/myshardrs02_27418/mongo.keyfile</span></span><br><span class="line"><span class="string">/mongodb/sharded_cluster/myshardrs02_27518/mongo.keyfile</span></span><br><span class="line"><span class="string">/mongodb/sharded_cluster/myconfigrs_27019/mongo.keyfile</span></span><br><span class="line"><span class="string">/mongodb/sharded_cluster/myconfigrs_27119/mongo.keyfile</span></span><br><span class="line"><span class="string">/mongodb/sharded_cluster/myconfigrs_27219/mongo.keyfile</span></span><br><span class="line"><span class="string">/mongodb/sharded_cluster/mymongos_27017/mongo.keyfile</span></span><br><span class="line"><span class="string">/mongodb/sharded_cluster/mymongos_27117/mongo.keyfile'</span> | xargs -n 1 cp -v /root/mongo.keyfile</span><br></pre></td></tr></table></figure>

<h3 id="3-4-3-修改配置文件指定keyfile"><a href="#3-4-3-修改配置文件指定keyfile" class="headerlink" title="3.4.3    修改配置文件指定keyfile"></a>3.4.3    修改配置文件指定keyfile</h3><p>分别编辑几个服务的mongod.conf文件，添加相关内容：</p>
<p>/mongodb/sharded_cluster/myshardrs01_27018/mongod.conf</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">security:</span></span><br><span class="line">    <span class="comment">#KeyFile鉴权文件</span></span><br><span class="line">    <span class="attr">keyFile:</span> <span class="string">/mongodb/sharded_cluster/myshardrs01_27018/mongo.keyfile</span></span><br><span class="line">    <span class="comment">#开启认证方式运行</span></span><br><span class="line">    <span class="attr">authorization:</span> <span class="string">enabled</span></span><br></pre></td></tr></table></figure>

<p>/mongodb/sharded_cluster/myshardrs01_27118/mongod.conf</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">security:</span></span><br><span class="line">    <span class="comment">#KeyFile鉴权文件</span></span><br><span class="line">    <span class="attr">keyFile:</span> <span class="string">/mongodb/sharded_cluster/myshardrs01_27118/mongo.keyfile</span></span><br><span class="line">    <span class="comment">#开启认证方式运行</span></span><br><span class="line">    <span class="attr">authorization:</span> <span class="string">enabled</span></span><br></pre></td></tr></table></figure>

<p>/mongodb/sharded_cluster/myshardrs01_27218/mongod.conf</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">security:</span></span><br><span class="line">    <span class="comment">#KeyFile鉴权文件</span></span><br><span class="line">    <span class="attr">keyFile:</span> <span class="string">/mongodb/sharded_cluster/myshardrs01_27218/mongo.keyfile</span></span><br><span class="line">    <span class="comment">#开启认证方式运行</span></span><br><span class="line">    <span class="attr">authorization:</span> <span class="string">enabled</span></span><br></pre></td></tr></table></figure>

<p>/mongodb/sharded_cluster/myshardrs02_27318/mongod.conf</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">security:</span></span><br><span class="line">    <span class="comment">#KeyFile鉴权文件</span></span><br><span class="line">    <span class="attr">keyFile:</span> <span class="string">/mongodb/sharded_cluster/myshardrs02_27318/mongo.keyfile</span></span><br><span class="line">    <span class="comment">#开启认证方式运行</span></span><br><span class="line">    <span class="attr">authorization:</span> <span class="string">enabled</span></span><br></pre></td></tr></table></figure>

<p>/mongodb/sharded_cluster/myshardrs02_27418/mongod.conf</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">security:</span></span><br><span class="line">    <span class="comment">#KeyFile鉴权文件</span></span><br><span class="line">    <span class="attr">keyFile:</span> <span class="string">/mongodb/sharded_cluster/myshardrs02_27418/mongo.keyfile</span></span><br><span class="line">    <span class="comment">#开启认证方式运行</span></span><br><span class="line">    <span class="attr">authorization:</span> <span class="string">enabled</span></span><br></pre></td></tr></table></figure>

<p>/mongodb/sharded_cluster/myshardrs02_27518/mongod.conf</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">security:</span></span><br><span class="line">    <span class="comment">#KeyFile鉴权文件</span></span><br><span class="line">    <span class="attr">keyFile:</span> <span class="string">/mongodb/sharded_cluster/myshardrs02_27518/mongo.keyfile</span></span><br><span class="line">    <span class="comment">#开启认证方式运行</span></span><br><span class="line">    <span class="attr">authorization:</span> <span class="string">enabled</span></span><br></pre></td></tr></table></figure>

<p>/mongodb/sharded_cluster/myconfigrs_27019/mongod.conf</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">security:</span></span><br><span class="line">    <span class="comment">#KeyFile鉴权文件</span></span><br><span class="line">    <span class="attr">keyFile:</span> <span class="string">/mongodb/sharded_cluster/myconfigrs_27019/mongo.keyfile</span></span><br><span class="line">    <span class="comment">#开启认证方式运行</span></span><br><span class="line">    <span class="attr">authorization:</span> <span class="string">enabled</span></span><br></pre></td></tr></table></figure>

<p>/mongodb/sharded_cluster/myconfigrs_27119/mongod.conf</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">security:</span></span><br><span class="line">    <span class="comment">#KeyFile鉴权文件</span></span><br><span class="line">    <span class="attr">keyFile:</span> <span class="string">/mongodb/sharded_cluster/myconfigrs_27119/mongo.keyfile</span></span><br><span class="line">    <span class="comment">#开启认证方式运行</span></span><br><span class="line">    <span class="attr">authorization:</span> <span class="string">enabled</span></span><br></pre></td></tr></table></figure>

<p>/mongodb/sharded_cluster/myconfigrs_27219/mongod.conf</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">security:</span></span><br><span class="line">    <span class="comment">#KeyFile鉴权文件</span></span><br><span class="line">    <span class="attr">keyFile:</span> <span class="string">/mongodb/sharded_cluster/myconfigrs_27219/mongo.keyfile</span></span><br><span class="line">    <span class="comment">#开启认证方式运行</span></span><br><span class="line">    <span class="attr">authorization:</span> <span class="string">enabled</span></span><br></pre></td></tr></table></figure>

<p>/mongodb/sharded_cluster/mymongos_27017/mongos.conf</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">security:</span></span><br><span class="line">    <span class="comment">#KeyFile鉴权文件</span></span><br><span class="line">    <span class="attr">keyFile:</span> <span class="string">/mongodb/sharded_cluster/mymongos_27017/mongo.keyfile</span></span><br></pre></td></tr></table></figure>

<p>/mongodb/sharded_cluster/mymongos_27117/mongos.conf</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">security:</span></span><br><span class="line">    <span class="comment">#KeyFile鉴权文件</span></span><br><span class="line">    <span class="attr">keyFile:</span> <span class="string">/mongodb/sharded_cluster/mymongos_27117/mongo.keyfile</span></span><br></pre></td></tr></table></figure>

<p>mongos 比mongod少了authorization：enabled的配置。原因是，副本集加分片的安全认证需要配置两方面的，副本集各个节点之间使用内部身份验证，用于内部各个mongo实例的通信，只有相同keyfile才能相互访问。所以都要开启 keyFile: /mongodb/sharded_cluster/mymongos_27117/mongo.keyfile 。</p>
<p>然而对于所有的mongod，才是真正的保存数据的分片。mongos只做路由，不保存数据。所以所有的mongod开启访问数据的授权authorization:enabled。这样用户只有账号密码正确才能访问到数据。</p>
<h3 id="3-4-4-重新启动节点"><a href="#3-4-4-重新启动节点" class="headerlink" title="3.4.4    重新启动节点"></a>3.4.4    重新启动节点</h3><p>必须依次启动配置节点、分片节点、路由节点：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myconfigrs_27019/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myconfigrs_27119/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myconfigrs_27219/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs01_27018/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs01_27118/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs01_27218/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs02_27318/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs02_27418/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongod -f /mongodb/sharded_cluster/myshardrs02_27518/mongod.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongos -f /mongodb/sharded_cluster/mymongos_27017/mongos.conf</span><br><span class="line">/usr/<span class="built_in">local</span>/mongodb/bin/mongos -f /mongodb/sharded_cluster/mymongos_27117/mongos.conf</span><br></pre></td></tr></table></figure>

<p>注意：</p>
<p>这里有个非常特别的情况，就是启动顺序。先启动配置节点，再启动分片节点，最后启动路由节点。</p>
<p>如果先启动分片节点，会卡住，提示：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">about to fork child process, waiting until server is ready for connections</span><br></pre></td></tr></table></figure>

<p>这也许是个 bug。原因未知。</p>
<h3 id="3-3-5-创建帐号和认证"><a href="#3-3-5-创建帐号和认证" class="headerlink" title="3.3.5    创建帐号和认证"></a>3.3.5    创建帐号和认证</h3><p>客户端mongo，通过localhost登录任意一个mongos路由，</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost db]<span class="comment"># /usr/local/mongodb/bin/mongo --port 27017</span></span><br></pre></td></tr></table></figure>

<p>提示：相当于一个后门，只能在 admin下添加用户。</p>
<p>创建一个管理员帐号：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">mongos&gt; use admin</span><br><span class="line">switched to db admin</span><br><span class="line">mongos&gt;  db.createUser(&#123;user:&quot;myroot&quot;,pwd:&quot;123456&quot;,roles:[&quot;root&quot;]&#125;)</span><br><span class="line">Successfully added user: &#123; &quot;user&quot; : &quot;myroot&quot;, &quot;roles&quot; : [ &quot;root&quot; ] &#125;</span><br></pre></td></tr></table></figure>

<p>提示：如果在开启认证之前已经创建了管理员账号，这里可以忽略</p>
<p>创建一个普通权限帐号：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">mongos&gt; use admin</span><br><span class="line">switched to db admin</span><br><span class="line">mongos&gt; db.auth(&quot;myroot&quot;,&quot;123456&quot;)</span><br><span class="line">1</span><br><span class="line">mongos&gt; use articledb</span><br><span class="line">switched to db articledb</span><br><span class="line">mongos&gt; db.createUser(&#123;user: &quot;bobo&quot;, pwd: &quot;123456&quot;, roles: [&#123; role: &quot;readWrite&quot;,db: &quot;articledb&quot; &#125;]&#125;)</span><br><span class="line">Successfully added user: &#123;</span><br><span class="line">    &quot;user&quot; : &quot;bobo&quot;,</span><br><span class="line">    &quot;roles&quot; : [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;role&quot; : &quot;readWrite&quot;,</span><br><span class="line">          &quot;db&quot; : &quot;articledb&quot;</span><br><span class="line">        &#125;</span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br><span class="line">mongos&gt; db.auth(&quot;bobo&quot;,&quot;123456&quot;)</span><br><span class="line">1</span><br></pre></td></tr></table></figure>

<p>提示：</p>
<p>通过mongos添加的账号信息，只会保存到配置节点的服务中，具体的数据节点不保存账号信息，因此，分片中的账号信息不涉及到同步问题。</p>
<p>mongo客户端登录mongos路由，用管理员帐号登录可查看分片情况：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">mongos&gt; use admin</span><br><span class="line">switched to db admin</span><br><span class="line">mongos&gt;  db.auth(&quot;myroot&quot;,&quot;123456&quot;)</span><br><span class="line">1</span><br><span class="line">mongos&gt; sh.status()</span><br></pre></td></tr></table></figure>

<p>退出连接，重新连接服务，使用普通权限帐号访问数据：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">[root@bobohost db]# &#x2F;usr&#x2F;local&#x2F;mongodb&#x2F;bin&#x2F;mongo --host 180.76.159.126 --port 27017</span><br><span class="line">MongoDB shell version v4.0.10</span><br><span class="line">connecting to: mongodb:&#x2F;&#x2F;180.76.159.126:27017&#x2F;?gssapiServiceName&#x3D;mongodb</span><br><span class="line">Implicit session: session &#123; &quot;id&quot; : UUID(&quot;6f84fa91-2414-407e-b3ab-c0b7eedde825&quot;)</span><br><span class="line">&#125;</span><br><span class="line">MongoDB server version: 4.0.10</span><br><span class="line">mongos&gt; use articledb</span><br><span class="line">switched to db articledb</span><br><span class="line">mongos&gt; db.auth(&quot;bobo&quot;,&quot;123456&quot;)</span><br><span class="line">1</span><br><span class="line">mongos&gt; show collections</span><br><span class="line">comment</span><br><span class="line">comment2</span><br><span class="line">mongos&gt; db.comment.count()</span><br><span class="line">10001</span><br></pre></td></tr></table></figure>

<h3 id="3-3-6-SpringDataMongoDB连接认证"><a href="#3-3-6-SpringDataMongoDB连接认证" class="headerlink" title="3.3.6    SpringDataMongoDB连接认证"></a>3.3.6    SpringDataMongoDB连接认证</h3><p>使用用户名和密码连接到 MongoDB 服务器，你必须使用<code>&#39;username:password@hostname/dbname&#39;</code> 格式，’username’为用户名，’password’ 为密码。</p>
<p>目标：使用用户bobo使用密码 123456 连接到MongoDB 服务上。</p>
<p>application.yml：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">    <span class="comment">#数据源配置</span></span><br><span class="line">    <span class="attr">data:</span></span><br><span class="line">        <span class="attr">mongodb:</span></span><br><span class="line">        <span class="comment"># 分片集群有认证的情况下，字符串连接</span></span><br><span class="line">        	<span class="attr">uri:</span> <span class="string">mongodb://bobo:123456@180.76.159.126:27017,180.76.159.126:27117/articledb</span></span><br></pre></td></tr></table></figure>


      
      <!-- 添加本文结束标记-->
      
           
             <div class="essayending">
               <div>
                <div style="text-align:center;color: #ccc;font-size:22px;">
                <br/>
                <br/>
                -------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------
                <br/>
                <br/>
                 <br/>
                 <br/>
                </div>
               </div>
             </div>
           
       
       <!-- 添加完成 -->
      <!-- 增加版权声明 -->
      
      
        <div class="declare">
          <strong>本文作者：</strong>
          
            Wgy
          
          <br>
          <strong>本文标题：</strong>
          <a rel="license" href="https://wgy1993.gitee.io/archives/afe7047c.html">MongoDB(二)</a>
          <br>
          <strong>本文链接：</strong>
          <a rel="license" href="https://wgy1993.gitee.io/archives/afe7047c.html">https://wgy1993.gitee.io/archives/afe7047c.html</a>
          <br>
          <strong>版权声明：</strong>
          本作品采用
          <a rel="license noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" title="知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议">CC BY-NC-SA 4.0</a>
          进行许可。转载请注明出处！
          
            <br>
            <a rel="license noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank"><img alt="知识共享许可协议" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png"/></a>
          
        </div>
      
      <!-- 增加版权声明结束 -->
      
        <div class="page-reward">
          <a href="javascript:;" class="page-reward-btn tooltip-top">
            <div class="tooltip tooltip-east">
            <span class="tooltip-item">
              赏
            </span>
            <span class="tooltip-content">
              <span class="tooltip-text">
                <span class="tooltip-inner">
                  <p class="reward-p"><i class="icon icon-quo-left"></i>谢谢你请我吃糖果<i class="icon icon-quo-right"></i></p>
                  <div class="reward-box">
                    
                    <div class="reward-box-item">
                      <img class="reward-img" src="/assets/img/alipay.jpg">
                      <span class="reward-type">支付宝</span>
                    </div>
                    
                    
                    <div class="reward-box-item">
                      <img class="reward-img" src="/assets/img/weixin.jpg">
                      <span class="reward-type">微信</span>
                    </div>
                    
                  </div>
                </span>
              </span>
            </span>
          </div>
          </a>
        </div>
      
    </div>
    <div class="article-info article-info-index">
      
      
	<div class="article-tag tagcloud">
		<i class="icon-price-tags icon"></i>
		<ul class="article-tag-list">
			 
        		<li class="article-tag-list-item">
        			<a href="javascript:void(0)" class="js-tag article-tag-list-link color3">NoSQL存储</a>
        		</li>
      		 
        		<li class="article-tag-list-item">
        			<a href="javascript:void(0)" class="js-tag article-tag-list-link color3">MongoDB</a>
        		</li>
      		
		</ul>
	</div>

      
	<div class="article-category tagcloud">
		<i class="icon-book icon"></i>
		<ul class="article-tag-list">
			 
        		<li class="article-tag-list-item">
        			<a href="/categories/服务器中间件//" class="article-tag-list-link color2">服务器中间件</a>
        		</li>
      		
		</ul>
	</div>


      

      
        
<div class="share-btn share-icons tooltip-left">
  <div class="tooltip tooltip-east">
    <span class="tooltip-item">
      <a href="javascript:;" class="share-sns share-outer">
        <i class="icon icon-share"></i>
      </a>
    </span>
    <span class="tooltip-content">
      <div class="share-wrap">
        <div class="share-icons">
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="icon icon-weibo"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="icon icon-weixin"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="icon icon-qq"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="icon icon-douban"></i>
          </a>
          <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a>
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="icon icon-facebook"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="icon icon-twitter"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="icon icon-google"></i>
          </a>
        </div>
      </div>
    </span>
  </div>
</div>

<div class="page-modal wx-share js-wx-box">
    <a class="close js-modal-close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//pan.baidu.com/share/qrcode?url=https://wgy1993.gitee.io/archives/afe7047c.html" alt="微信分享二维码">
    </div>
</div>

<div class="mask js-mask"></div>
      
      <div class="clearfix"></div>
    </div>
  </div>
</article>

  
<nav id="article-nav">
  
    <a href="/archives/a2f2c444.html" id="article-nav-newer" class="article-nav-link-wrap">
      <i class="icon-circle-left"></i>
      <div class="article-nav-title">
        
          SpringData(一)
        
      </div>
    </a>
  
  
    <a href="/archives/c09edc62.html" id="article-nav-older" class="article-nav-link-wrap">
      <div class="article-nav-title">Linux(三)</div>
      <i class="icon-circle-right"></i>
    </a>
  
</nav>


<aside class="wrap-side-operation">
    <div class="mod-side-operation">
        
        <div class="jump-container" id="js-jump-container" style="display:none;">
            <a href="javascript:void(0)" class="mod-side-operation__jump-to-top">
                <i class="icon-font icon-back"></i>
            </a>
            <div id="js-jump-plan-container" class="jump-plan-container" style="top: -11px;">
                <i class="icon-font icon-plane jump-plane"></i>
            </div>
        </div>
        
        
        <div class="toc-container tooltip-left">
            <i class="icon-font icon-category"></i>
            <div class="tooltip tooltip-east">
                <span class="tooltip-item">
                </span>
                <span class="tooltip-content">
                    <div class="toc-article">
                    <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#1-副本集-Replica-Sets"><span class="toc-number">1.</span> <span class="toc-text">1.    副本集-Replica Sets</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-1-简介"><span class="toc-number">1.1.</span> <span class="toc-text">1.1    简介</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-2-副本集的三个角色"><span class="toc-number">1.2.</span> <span class="toc-text">1.2    副本集的三个角色</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-3-副本集架构目标"><span class="toc-number">1.3.</span> <span class="toc-text">1.3    副本集架构目标</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-4-副本集的创建"><span class="toc-number">1.4.</span> <span class="toc-text">1.4    副本集的创建</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-4-1-第一步：创建主节点"><span class="toc-number">1.4.1.</span> <span class="toc-text">1.4.1    第一步：创建主节点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-4-2-第二步：创建副本节点"><span class="toc-number">1.4.2.</span> <span class="toc-text">1.4.2    第二步：创建副本节点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-4-3-第三步：创建仲裁节点"><span class="toc-number">1.4.3.</span> <span class="toc-text">1.4.3    第三步：创建仲裁节点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-4-4-第四步：初始化配置副本集和主节点"><span class="toc-number">1.4.4.</span> <span class="toc-text">1.4.4    第四步：初始化配置副本集和主节点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-4-5-第五步：查看副本集的配置内容"><span class="toc-number">1.4.5.</span> <span class="toc-text">1.4.5    第五步：查看副本集的配置内容</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-4-6-第六步：查看副本集状态"><span class="toc-number">1.4.6.</span> <span class="toc-text">1.4.6    第六步：查看副本集状态</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-4-7-第七步：添加副本从节点"><span class="toc-number">1.4.7.</span> <span class="toc-text">1.4.7    第七步：添加副本从节点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-4-8-第八步：添加仲裁从节点"><span class="toc-number">1.4.8.</span> <span class="toc-text">1.4.8    第八步：添加仲裁从节点</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-5-副本集的数据读写操作"><span class="toc-number">1.5.</span> <span class="toc-text">1.5    副本集的数据读写操作</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-6-主节点的选举原则"><span class="toc-number">1.6.</span> <span class="toc-text">1.6    主节点的选举原则</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-7-故障测试"><span class="toc-number">1.7.</span> <span class="toc-text">1.7    故障测试</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-7-1-副本节点故障测试"><span class="toc-number">1.7.1.</span> <span class="toc-text">1.7.1    副本节点故障测试</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-7-2-主节点故障测试"><span class="toc-number">1.7.2.</span> <span class="toc-text">1.7.2    主节点故障测试</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-7-3-仲裁节点和主节点故障"><span class="toc-number">1.7.3.</span> <span class="toc-text">1.7.3    仲裁节点和主节点故障</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-7-4-仲裁节点和从节点故障"><span class="toc-number">1.7.4.</span> <span class="toc-text">1.7.4    仲裁节点和从节点故障</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-8-Compass-连接副本集"><span class="toc-number">1.8.</span> <span class="toc-text">1.8    Compass 连接副本集</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-9-SpringDataMongoDB-连接副本集"><span class="toc-number">1.9.</span> <span class="toc-text">1.9    SpringDataMongoDB 连接副本集</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#2-分片集群-Sharded-Cluster"><span class="toc-number">2.</span> <span class="toc-text">2.    分片集群-Sharded Cluster</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#2-1-分片概念"><span class="toc-number">2.1.</span> <span class="toc-text">2.1    分片概念</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-2-分片集群包含的组件"><span class="toc-number">2.2.</span> <span class="toc-text">2.2    分片集群包含的组件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-3-分片集群架构目标"><span class="toc-number">2.3.</span> <span class="toc-text">2.3    分片集群架构目标</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-4-分片（存储）节点副本集的创建"><span class="toc-number">2.4.</span> <span class="toc-text">2.4    分片（存储）节点副本集的创建</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-4-1-第一套副本集"><span class="toc-number">2.4.1.</span> <span class="toc-text">2.4.1    第一套副本集</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#2-4-1-1-初始化副本集和创建主节点："><span class="toc-number">2.4.1.1.</span> <span class="toc-text">2.4.1.1    初始化副本集和创建主节点：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-4-1-2-添加副本节点"><span class="toc-number">2.4.1.2.</span> <span class="toc-text">2.4.1.2    添加副本节点</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-4-1-3-添加仲裁节点"><span class="toc-number">2.4.1.3.</span> <span class="toc-text">2.4.1.3    添加仲裁节点</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-4-2-第二套副本集"><span class="toc-number">2.4.2.</span> <span class="toc-text">2.4.2    第二套副本集</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#2-4-2-1-初始化副本集和创建主节点"><span class="toc-number">2.4.2.1.</span> <span class="toc-text">2.4.2.1    初始化副本集和创建主节点</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-4-2-2-添加副本节点"><span class="toc-number">2.4.2.2.</span> <span class="toc-text">2.4.2.2    添加副本节点</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-4-2-3-添加仲裁节点"><span class="toc-number">2.4.2.3.</span> <span class="toc-text">2.4.2.3    添加仲裁节点</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-5-配置节点副本集的创建"><span class="toc-number">2.5.</span> <span class="toc-text">2.5    配置节点副本集的创建</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-5-1-初始化副本集和创建主节点"><span class="toc-number">2.5.1.</span> <span class="toc-text">2.5.1    初始化副本集和创建主节点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-5-2-添加两个副本节点"><span class="toc-number">2.5.2.</span> <span class="toc-text">2.5.2    添加两个副本节点</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-6-路由节点的创建和操作"><span class="toc-number">2.6.</span> <span class="toc-text">2.6    路由节点的创建和操作</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-6-1-第一个路由节点的创建和连接"><span class="toc-number">2.6.1.</span> <span class="toc-text">2.6.1    第一个路由节点的创建和连接</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-6-2-在路由节点上进行分片配置操作"><span class="toc-number">2.6.2.</span> <span class="toc-text">2.6.2    在路由节点上进行分片配置操作</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#2-6-2-1-添加分片："><span class="toc-number">2.6.2.1.</span> <span class="toc-text">2.6.2.1    添加分片：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-6-2-2-开启分片功能"><span class="toc-number">2.6.2.2.</span> <span class="toc-text">2.6.2.2    开启分片功能</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-6-2-3-集合分片"><span class="toc-number">2.6.2.3.</span> <span class="toc-text">2.6.2.3    集合分片</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-6-3-分片后插入数据测试"><span class="toc-number">2.6.3.</span> <span class="toc-text">2.6.3    分片后插入数据测试</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-6-4-再增加一个路由节点"><span class="toc-number">2.6.4.</span> <span class="toc-text">2.6.4    再增加一个路由节点</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-7-Compass-连接分片集群"><span class="toc-number">2.7.</span> <span class="toc-text">2.7    Compass 连接分片集群</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-8-SpringDataMongDB-连接分片集群"><span class="toc-number">2.8.</span> <span class="toc-text">2.8    SpringDataMongDB 连接分片集群</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-9-清除所有的节点数据（备用）"><span class="toc-number">2.9.</span> <span class="toc-text">2.9    清除所有的节点数据（备用）</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#3-安全认证"><span class="toc-number">3.</span> <span class="toc-text">3.    安全认证</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#3-1-MongoDB-的用户和角色权限简介"><span class="toc-number">3.1.</span> <span class="toc-text">3.1    MongoDB 的用户和角色权限简介</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-2-单实例环境"><span class="toc-number">3.2.</span> <span class="toc-text">3.2    单实例环境</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-2-1-关闭已开启的服务"><span class="toc-number">3.2.1.</span> <span class="toc-text">3.2.1    关闭已开启的服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-2-2-添加用户和权限"><span class="toc-number">3.2.2.</span> <span class="toc-text">3.2.2    添加用户和权限</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-2-3-服务端开启认证和客户端连接登录"><span class="toc-number">3.2.3.</span> <span class="toc-text">3.2.3    服务端开启认证和客户端连接登录</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#3-2-3-1-关闭已经启动的服务"><span class="toc-number">3.2.3.1.</span> <span class="toc-text">3.2.3.1    关闭已经启动的服务</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-2-3-2-以开启认证的方式启动服务"><span class="toc-number">3.2.3.2.</span> <span class="toc-text">3.2.3.2    以开启认证的方式启动服务</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-2-3-3-开启了认证的情况下的客户端登录"><span class="toc-number">3.2.3.3.</span> <span class="toc-text">3.2.3.3    开启了认证的情况下的客户端登录</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-2-4-SpringDataMongoDB连接认证"><span class="toc-number">3.2.4.</span> <span class="toc-text">3.2.4    SpringDataMongoDB连接认证</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-3-副本集环境"><span class="toc-number">3.3.</span> <span class="toc-text">3.3    副本集环境</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-3-1-前言"><span class="toc-number">3.3.1.</span> <span class="toc-text">3.3.1    前言</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-3-2-关闭已开启的副本集服务"><span class="toc-number">3.3.2.</span> <span class="toc-text">3.3.2    关闭已开启的副本集服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-3-3-通过主节点添加一个管理员帐号"><span class="toc-number">3.3.3.</span> <span class="toc-text">3.3.3    通过主节点添加一个管理员帐号</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-3-4-创建副本集认证的key文件"><span class="toc-number">3.3.4.</span> <span class="toc-text">3.3.4    创建副本集认证的key文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-3-5-修改配置文件指定keyfile"><span class="toc-number">3.3.5.</span> <span class="toc-text">3.3.5    修改配置文件指定keyfile</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-3-6-重新启动副本集"><span class="toc-number">3.3.6.</span> <span class="toc-text">3.3.6    重新启动副本集</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-3-7-在主节点上添加普通账号"><span class="toc-number">3.3.7.</span> <span class="toc-text">3.3.7    在主节点上添加普通账号</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-3-8-SpringDataMongoDB连接副本集"><span class="toc-number">3.3.8.</span> <span class="toc-text">3.3.8    SpringDataMongoDB连接副本集</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-4-分片集群环境-扩展"><span class="toc-number">3.4.</span> <span class="toc-text">3.4    分片集群环境(扩展)</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-4-1-关闭已开启的集群服务"><span class="toc-number">3.4.1.</span> <span class="toc-text">3.4.1    关闭已开启的集群服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-4-2-创建副本集认证的key文件"><span class="toc-number">3.4.2.</span> <span class="toc-text">3.4.2    创建副本集认证的key文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-4-3-修改配置文件指定keyfile"><span class="toc-number">3.4.3.</span> <span class="toc-text">3.4.3    修改配置文件指定keyfile</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-4-4-重新启动节点"><span class="toc-number">3.4.4.</span> <span class="toc-text">3.4.4    重新启动节点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-3-5-创建帐号和认证"><span class="toc-number">3.4.5.</span> <span class="toc-text">3.3.5    创建帐号和认证</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-3-6-SpringDataMongoDB连接认证"><span class="toc-number">3.4.6.</span> <span class="toc-text">3.3.6    SpringDataMongoDB连接认证</span></a></li></ol></li></ol></li></ol>
                    </div>
                </span>
            </div>
        </div>
        
    </div>
</aside>



  

  

  

  

  

  
    <div id="gitalk-container" style="padding: 0px 30px 0px 30px;"></div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<script type="text/javascript">

if(true){
	var gitalk = new Gitalk({
  	clientID: 'a01b13554e910b682a17',
  	clientSecret: 'ed78fef4c5012669cf340214fd17d583601a9aa1',
  	repo: 'wgy1993.github.io',
  	owner: 'wgy1993',
  	admin: ['wgy1993'],
  	id: 'Fri Sep 18 2020 16:54:22 GMT+0800',
  	distractionFreeMode: 'true'
})
gitalk.render('gitalk-container')
}
</script>

  
  <br/>


          </div>
        </div>
      </div>
      <footer id="footer">
  <div class="outer">
    <div id="footer-info">
    	<div class="footer-left">
    		&copy; 2021 Wgy
    	</div>
      	<div class="footer-right">
      		<a href="http://hexo.io/" target="_blank">Hexo</a>  Theme <a href="https://github.com/litten/hexo-theme-yilia" target="_blank">Yilia</a> by Litten
      	</div>
    </div>
  </div>
  <!-- 开始添加本站访客数-->
  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
  <span id="busuanzi_container_site_pv">
      本站总访问量: <span id="busuanzi_value_site_pv"></span>
  </span>
  <!-- 添加完成 -->
  <!--页面点击小红心-->
  <script type="text/javascript" src="/love.js"></script>
</footer>

    </div>
    <script>
	var yiliaConfig = {
		mathjax: false,
		isHome: false,
		isPost: true,
		isArchive: false,
		isTag: false,
		isCategory: false,
		open_in_new: false,
		toc_hide_index: true,
		root: "/",
		innerArchive: true,
		showTags: true
	}
</script>

<script>!function(r){function e(t){if(i[t])return i[t].exports;var n=i[t]={exports:{},id:t,loaded:!1};return r[t].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var i={};e.m=r,e.c=i,e.p="./",e(0)}([function(t,n,r){r(209),t.exports=r(205)},function(t,n,r){var d=r(3),y=r(46),g=r(26),b=r(27),x=r(47),m="prototype",S=function(t,n,r){var e,i,o,u,c=t&S.F,f=t&S.G,a=t&S.S,s=t&S.P,l=t&S.B,h=f?d:a?d[n]||(d[n]={}):(d[n]||{})[m],v=f?y:y[n]||(y[n]={}),p=v[m]||(v[m]={});for(e in f&&(r=n),r)o=((i=!c&&h&&void 0!==h[e])?h:r)[e],u=l&&i?x(o,d):s&&"function"==typeof o?x(Function.call,o):o,h&&b(h,e,o,t&S.U),v[e]!=o&&g(v,e,u),s&&p[e]!=o&&(p[e]=o)};d.core=y,S.F=1,S.G=2,S.S=4,S.P=8,S.B=16,S.W=32,S.U=64,S.R=128,t.exports=S},function(t,n,r){var e=r(5);t.exports=function(t){if(!e(t))throw TypeError(t+" is not an object!");return t}},function(t,n){var r=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=r)},function(t,n){t.exports=function(t){try{return!!t()}catch(t){return!0}}},function(t,n){t.exports=function(t){return"object"==typeof t?null!==t:"function"==typeof t}},function(t,n){var r=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=r)},function(t,n,r){var e=r(118)("wks"),i=r(79),o=r(3).Symbol,u="function"==typeof o;(t.exports=function(t){return e[t]||(e[t]=u&&o[t]||(u?o:i)("Symbol."+t))}).store=e},function(t,n,r){var e=r(49),i=Math.min;t.exports=function(t){return 0<t?i(e(t),9007199254740991):0}},function(t,n){var r={}.hasOwnProperty;t.exports=function(t,n){return r.call(t,n)}},function(t,n,r){t.exports=!r(4)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(t,n,r){var e=r(2),i=r(174),o=r(53),u=Object.defineProperty;n.f=r(10)?Object.defineProperty:function(t,n,r){if(e(t),n=o(n,!0),e(r),i)try{return u(t,n,r)}catch(t){}if("get"in r||"set"in r)throw TypeError("Accessors not supported!");return"value"in r&&(t[n]=r.value),t}},function(t,n,r){t.exports=!r(20)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(t,n,r){var e=r(14),i=r(24);t.exports=r(12)?function(t,n,r){return e.f(t,n,i(1,r))}:function(t,n,r){return t[n]=r,t}},function(t,n,r){var e=r(22),i=r(60),o=r(42),u=Object.defineProperty;n.f=r(12)?Object.defineProperty:function(t,n,r){if(e(t),n=o(n,!0),e(r),i)try{return u(t,n,r)}catch(t){}if("get"in r||"set"in r)throw TypeError("Accessors not supported!");return"value"in r&&(t[n]=r.value),t}},function(t,n,r){var e=r(96),i=r(34);t.exports=function(t){return e(i(t))}},function(t,n,r){var e=r(40)("wks"),i=r(25),o=r(6).Symbol,u="function"==typeof o;(t.exports=function(t){return e[t]||(e[t]=u&&o[t]||(u?o:i)("Symbol."+t))}).store=e},function(t,n,r){var e=r(51);t.exports=function(t){return Object(e(t))}},function(t,n){t.exports=function(t){return"object"==typeof t?null!==t:"function"==typeof t}},function(t,n){var r=t.exports={version:"2.6.11"};"number"==typeof __e&&(__e=r)},function(t,n){t.exports=function(t){try{return!!t()}catch(t){return!0}}},function(t,n){t.exports=function(t){if("function"!=typeof t)throw TypeError(t+" is not a function!");return t}},function(t,n,r){var e=r(18);t.exports=function(t){if(!e(t))throw TypeError(t+" is not an object!");return t}},function(t,n){t.exports=!0},function(t,n){t.exports=function(t,n){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:n}}},function(t,n){var r=0,e=Math.random();t.exports=function(t){return"Symbol(".concat(void 0===t?"":t,")_",(++r+e).toString(36))}},function(t,n,r){var e=r(11),i=r(75);t.exports=r(10)?function(t,n,r){return e.f(t,n,i(1,r))}:function(t,n,r){return t[n]=r,t}},function(t,n,r){var o=r(3),u=r(26),c=r(30),f=r(79)("src"),e=r(221),i="toString",a=(""+e).split(i);r(46).inspectSource=function(t){return e.call(t)},(t.exports=function(t,n,r,e){var i="function"==typeof r;i&&(c(r,"name")||u(r,"name",n)),t[n]!==r&&(i&&(c(r,f)||u(r,f,t[n]?""+t[n]:a.join(String(n)))),t===o?t[n]=r:e?t[n]?t[n]=r:u(t,n,r):(delete t[n],u(t,n,r)))})(Function.prototype,i,function(){return"function"==typeof this&&this[f]||e.call(this)})},function(t,n,r){var e=r(1),i=r(4),u=r(51),c=/"/g,o=function(t,n,r,e){var i=String(u(t)),o="<"+n;return""!==r&&(o+=" "+r+'="'+String(e).replace(c,"&quot;")+'"'),o+">"+i+"</"+n+">"};t.exports=function(n,t){var r={};r[n]=t(o),e(e.P+e.F*i(function(){var t=""[n]('"');return t!==t.toLowerCase()||3<t.split('"').length}),"String",r)}},function(t,n,r){var e=r(65),i=r(35);t.exports=Object.keys||function(t){return e(t,i)}},function(t,n){var r={}.hasOwnProperty;t.exports=function(t,n){return r.call(t,n)}},function(t,n,r){var e=r(117),i=r(75),o=r(33),u=r(53),c=r(30),f=r(174),a=Object.getOwnPropertyDescriptor;n.f=r(10)?a:function(t,n){if(t=o(t),n=u(n,!0),f)try{return a(t,n)}catch(t){}if(c(t,n))return i(!e.f.call(t,n),t[n])}},function(t,n,r){var e=r(30),i=r(17),o=r(154)("IE_PROTO"),u=Object.prototype;t.exports=Object.getPrototypeOf||function(t){return t=i(t),e(t,o)?t[o]:"function"==typeof t.constructor&&t instanceof t.constructor?t.constructor.prototype:t instanceof Object?u:null}},function(t,n,r){var e=r(116),i=r(51);t.exports=function(t){return e(i(t))}},function(t,n){t.exports=function(t){if(null==t)throw TypeError("Can't call method on  "+t);return t}},function(t,n){t.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},function(t,n){t.exports={}},function(t,n){n.f={}.propertyIsEnumerable},function(t,n,r){var e=r(14).f,i=r(9),o=r(16)("toStringTag");t.exports=function(t,n,r){t&&!i(t=r?t:t.prototype,o)&&e(t,o,{configurable:!0,value:n})}},function(t,n,r){var e=r(40)("keys"),i=r(25);t.exports=function(t){return e[t]||(e[t]=i(t))}},function(t,n,r){var e=r(19),i=r(6),o="__core-js_shared__",u=i[o]||(i[o]={});(t.exports=function(t,n){return u[t]||(u[t]=void 0!==n?n:{})})("versions",[]).push({version:e.version,mode:r(23)?"pure":"global",copyright:"© 2019 Denis Pushkarev (zloirock.ru)"})},function(t,n){var r=Math.ceil,e=Math.floor;t.exports=function(t){return isNaN(t=+t)?0:(0<t?e:r)(t)}},function(t,n,r){var i=r(18);t.exports=function(t,n){if(!i(t))return t;var r,e;if(n&&"function"==typeof(r=t.toString)&&!i(e=r.call(t)))return e;if("function"==typeof(r=t.valueOf)&&!i(e=r.call(t)))return e;if(!n&&"function"==typeof(r=t.toString)&&!i(e=r.call(t)))return e;throw TypeError("Can't convert object to primitive value")}},function(t,n,r){var e=r(6),i=r(19),o=r(23),u=r(44),c=r(14).f;t.exports=function(t){var n=i.Symbol||(i.Symbol=o?{}:e.Symbol||{});"_"==t.charAt(0)||t in n||c(n,t,{value:u.f(t)})}},function(t,n,r){n.f=r(16)},function(t,n){var r={}.toString;t.exports=function(t){return r.call(t).slice(8,-1)}},function(t,n){var r=t.exports={version:"2.6.11"};"number"==typeof __e&&(__e=r)},function(t,n,r){var o=r(21);t.exports=function(e,i,t){if(o(e),void 0===i)return e;switch(t){case 1:return function(t){return e.call(i,t)};case 2:return function(t,n){return e.call(i,t,n)};case 3:return function(t,n,r){return e.call(i,t,n,r)}}return function(){return e.apply(i,arguments)}}},function(t,n,r){"use strict";var e=r(4);t.exports=function(t,n){return!!t&&e(function(){n?t.call(null,function(){},1):t.call(null)})}},function(t,n){var r=Math.ceil,e=Math.floor;t.exports=function(t){return isNaN(t=+t)?0:(0<t?e:r)(t)}},function(t,n,r){var x=r(47),m=r(116),S=r(17),w=r(8),e=r(138);t.exports=function(l,t){var h=1==l,v=2==l,p=3==l,d=4==l,y=6==l,g=5==l||y,b=t||e;return function(t,n,r){for(var e,i,o=S(t),u=m(o),c=x(n,r,3),f=w(u.length),a=0,s=h?b(t,f):v?b(t,0):void 0;a<f;a++)if((g||a in u)&&(i=c(e=u[a],a,o),l))if(h)s[a]=i;else if(i)switch(l){case 3:return!0;case 5:return e;case 6:return a;case 2:s.push(e)}else if(d)return!1;return y?-1:p||d?d:s}}},function(t,n){t.exports=function(t){if(null==t)throw TypeError("Can't call method on  "+t);return t}},function(t,n,r){var i=r(1),o=r(46),u=r(4);t.exports=function(t,n){var r=(o.Object||{})[t]||Object[t],e={};e[t]=n(r),i(i.S+i.F*u(function(){r(1)}),"Object",e)}},function(t,n,r){var i=r(5);t.exports=function(t,n){if(!i(t))return t;var r,e;if(n&&"function"==typeof(r=t.toString)&&!i(e=r.call(t)))return e;if("function"==typeof(r=t.valueOf)&&!i(e=r.call(t)))return e;if(!n&&"function"==typeof(r=t.toString)&&!i(e=r.call(t)))return e;throw TypeError("Can't convert object to primitive value")}},function(t,n,r){var d=r(6),y=r(19),g=r(93),b=r(13),x=r(9),m="prototype",S=function(t,n,r){var e,i,o,u=t&S.F,c=t&S.G,f=t&S.S,a=t&S.P,s=t&S.B,l=t&S.W,h=c?y:y[n]||(y[n]={}),v=h[m],p=c?d:f?d[n]:(d[n]||{})[m];for(e in c&&(r=n),r)(i=!u&&p&&void 0!==p[e])&&x(h,e)||(o=i?p[e]:r[e],h[e]=c&&"function"!=typeof p[e]?r[e]:s&&i?g(o,d):l&&p[e]==o?function(e){var t=function(t,n,r){if(this instanceof e){switch(arguments.length){case 0:return new e;case 1:return new e(t);case 2:return new e(t,n)}return new e(t,n,r)}return e.apply(this,arguments)};return t[m]=e[m],t}(o):a&&"function"==typeof o?g(Function.call,o):o,a&&((h.virtual||(h.virtual={}))[e]=o,t&S.R&&v&&!v[e]&&b(v,e,o)))};S.F=1,S.G=2,S.S=4,S.P=8,S.B=16,S.W=32,S.U=64,S.R=128,t.exports=S},function(t,n,r){var e=r(34);t.exports=function(t){return Object(e(t))}},function(t,n,r){var o=r(196),e=r(1),i=r(118)("metadata"),u=i.store||(i.store=new(r(200))),c=function(t,n,r){var e=u.get(t);if(!e){if(!r)return;u.set(t,e=new o)}var i=e.get(n);if(!i){if(!r)return;e.set(n,i=new o)}return i};t.exports={store:u,map:c,has:function(t,n,r){var e=c(n,r,!1);return void 0!==e&&e.has(t)},get:function(t,n,r){var e=c(n,r,!1);return void 0===e?void 0:e.get(t)},set:function(t,n,r,e){c(r,e,!0).set(t,n)},keys:function(t,n){var r=c(t,n,!1),e=[];return r&&r.forEach(function(t,n){e.push(n)}),e},key:function(t){return void 0===t||"symbol"==typeof t?t:String(t)},exp:function(t){e(e.S,"Reflect",t)}}},function(t,n,r){"use strict";if(r(10)){var g=r(68),b=r(3),x=r(4),m=r(1),S=r(132),e=r(159),h=r(47),w=r(70),i=r(75),_=r(26),o=r(76),u=r(49),O=r(8),E=r(194),c=r(78),f=r(53),a=r(30),M=r(81),P=r(5),v=r(17),p=r(145),j=r(72),F=r(32),A=r(73).f,d=r(161),s=r(79),l=r(7),y=r(50),I=r(120),L=r(119),N=r(162),T=r(82),k=r(125),R=r(77),C=r(137),D=r(166),G=r(11),W=r(31),U=G.f,V=W.f,B=b.RangeError,q=b.TypeError,z=b.Uint8Array,H="ArrayBuffer",K="Shared"+H,J="BYTES_PER_ELEMENT",$="prototype",Y=Array[$],X=e.ArrayBuffer,Q=e.DataView,Z=y(0),tt=y(2),nt=y(3),rt=y(4),et=y(5),it=y(6),ot=I(!0),ut=I(!1),ct=N.values,ft=N.keys,at=N.entries,st=Y.lastIndexOf,lt=Y.reduce,ht=Y.reduceRight,vt=Y.join,pt=Y.sort,dt=Y.slice,yt=Y.toString,gt=Y.toLocaleString,bt=l("iterator"),xt=l("toStringTag"),mt=s("typed_constructor"),St=s("def_constructor"),wt=S.CONSTR,_t=S.TYPED,Ot=S.VIEW,Et="Wrong length!",Mt=y(1,function(t,n){return It(L(t,t[St]),n)}),Pt=x(function(){return 1===new z(new Uint16Array([1]).buffer)[0]}),jt=!!z&&!!z[$].set&&x(function(){new z(1).set({})}),Ft=function(t,n){var r=u(t);if(r<0||r%n)throw B("Wrong offset!");return r},At=function(t){if(P(t)&&_t in t)return t;throw q(t+" is not a typed array!")},It=function(t,n){if(!(P(t)&&mt in t))throw q("It is not a typed array constructor!");return new t(n)},Lt=function(t,n){return Nt(L(t,t[St]),n)},Nt=function(t,n){for(var r=0,e=n.length,i=It(t,e);r<e;)i[r]=n[r++];return i},Tt=function(t,n,r){U(t,n,{get:function(){return this._d[r]}})},kt=function(t){var n,r,e,i,o,u,c=v(t),f=arguments.length,a=1<f?arguments[1]:void 0,s=void 0!==a,l=d(c);if(null!=l&&!p(l)){for(u=l.call(c),e=[],n=0;!(o=u.next()).done;n++)e.push(o.value);c=e}for(s&&2<f&&(a=h(a,arguments[2],2)),n=0,r=O(c.length),i=It(this,r);n<r;n++)i[n]=s?a(c[n],n):c[n];return i},Rt=function(){for(var t=0,n=arguments.length,r=It(this,n);t<n;)r[t]=arguments[t++];return r},Ct=!!z&&x(function(){gt.call(new z(1))}),Dt=function(){return gt.apply(Ct?dt.call(At(this)):At(this),arguments)},Gt={copyWithin:function(t,n){return D.call(At(this),t,n,2<arguments.length?arguments[2]:void 0)},every:function(t){return rt(At(this),t,1<arguments.length?arguments[1]:void 0)},fill:function(t){return C.apply(At(this),arguments)},filter:function(t){return Lt(this,tt(At(this),t,1<arguments.length?arguments[1]:void 0))},find:function(t){return et(At(this),t,1<arguments.length?arguments[1]:void 0)},findIndex:function(t){return it(At(this),t,1<arguments.length?arguments[1]:void 0)},forEach:function(t){Z(At(this),t,1<arguments.length?arguments[1]:void 0)},indexOf:function(t){return ut(At(this),t,1<arguments.length?arguments[1]:void 0)},includes:function(t){return ot(At(this),t,1<arguments.length?arguments[1]:void 0)},join:function(t){return vt.apply(At(this),arguments)},lastIndexOf:function(t){return st.apply(At(this),arguments)},map:function(t){return Mt(At(this),t,1<arguments.length?arguments[1]:void 0)},reduce:function(t){return lt.apply(At(this),arguments)},reduceRight:function(t){return ht.apply(At(this),arguments)},reverse:function(){for(var t,n=this,r=At(n).length,e=Math.floor(r/2),i=0;i<e;)t=n[i],n[i++]=n[--r],n[r]=t;return n},some:function(t){return nt(At(this),t,1<arguments.length?arguments[1]:void 0)},sort:function(t){return pt.call(At(this),t)},subarray:function(t,n){var r=At(this),e=r.length,i=c(t,e);return new(L(r,r[St]))(r.buffer,r.byteOffset+i*r.BYTES_PER_ELEMENT,O((void 0===n?e:c(n,e))-i))}},Wt=function(t,n){return Lt(this,dt.call(At(this),t,n))},Ut=function(t){At(this);var n=Ft(arguments[1],1),r=this.length,e=v(t),i=O(e.length),o=0;if(r<i+n)throw B(Et);for(;o<i;)this[n+o]=e[o++]},Vt={entries:function(){return at.call(At(this))},keys:function(){return ft.call(At(this))},values:function(){return ct.call(At(this))}},Bt=function(t,n){return P(t)&&t[_t]&&"symbol"!=typeof n&&n in t&&String(+n)==String(n)},qt=function(t,n){return Bt(t,n=f(n,!0))?i(2,t[n]):V(t,n)},zt=function(t,n,r){return!(Bt(t,n=f(n,!0))&&P(r)&&a(r,"value"))||a(r,"get")||a(r,"set")||r.configurable||a(r,"writable")&&!r.writable||a(r,"enumerable")&&!r.enumerable?U(t,n,r):(t[n]=r.value,t)};wt||(W.f=qt,G.f=zt),m(m.S+m.F*!wt,"Object",{getOwnPropertyDescriptor:qt,defineProperty:zt}),x(function(){yt.call({})})&&(yt=gt=function(){return vt.call(this)});var Ht=o({},Gt);o(Ht,Vt),_(Ht,bt,Vt.values),o(Ht,{slice:Wt,set:Ut,constructor:function(){},toString:yt,toLocaleString:Dt}),Tt(Ht,"buffer","b"),Tt(Ht,"byteOffset","o"),Tt(Ht,"byteLength","l"),Tt(Ht,"length","e"),U(Ht,xt,{get:function(){return this[_t]}}),t.exports=function(t,l,n,o){var h=t+((o=!!o)?"Clamped":"")+"Array",r="get"+t,u="set"+t,v=b[h],c=v||{},e=v&&F(v),i=!v||!S.ABV,f={},a=v&&v[$],p=function(t,i){U(t,i,{get:function(){return t=i,(n=this._d).v[r](t*l+n.o,Pt);var t,n},set:function(t){return n=i,r=t,e=this._d,o&&(r=(r=Math.round(r))<0?0:255<r?255:255&r),void e.v[u](n*l+e.o,r,Pt);var n,r,e},enumerable:!0})};i?(v=n(function(t,n,r,e){w(t,v,h,"_d");var i,o,u,c,f=0,a=0;if(P(n)){if(!(n instanceof X||(c=M(n))==H||c==K))return _t in n?Nt(v,n):kt.call(v,n);i=n,a=Ft(r,l);var s=n.byteLength;if(void 0===e){if(s%l)throw B(Et);if((o=s-a)<0)throw B(Et)}else if(s<(o=O(e)*l)+a)throw B(Et);u=o/l}else u=E(n),i=new X(o=u*l);for(_(t,"_d",{b:i,o:a,l:o,e:u,v:new Q(i)});f<u;)p(t,f++)}),a=v[$]=j(Ht),_(a,"constructor",v)):x(function(){v(1)})&&x(function(){new v(-1)})&&k(function(t){new v,new v(null),new v(1.5),new v(t)},!0)||(v=n(function(t,n,r,e){var i;return w(t,v,h),P(n)?n instanceof X||(i=M(n))==H||i==K?void 0!==e?new c(n,Ft(r,l),e):void 0!==r?new c(n,Ft(r,l)):new c(n):_t in n?Nt(v,n):kt.call(v,n):new c(E(n))}),Z(e!==Function.prototype?A(c).concat(A(e)):A(c),function(t){t in v||_(v,t,c[t])}),v[$]=a,g||(a.constructor=v));var s=a[bt],d=!!s&&("values"==s.name||null==s.name),y=Vt.values;_(v,mt,!0),_(a,_t,h),_(a,Ot,!0),_(a,St,v),(o?new v(1)[xt]==h:xt in a)||U(a,xt,{get:function(){return h}}),f[h]=v,m(m.G+m.W+m.F*(v!=c),f),m(m.S,h,{BYTES_PER_ELEMENT:l}),m(m.S+m.F*x(function(){c.of.call(v,1)}),h,{from:kt,of:Rt}),J in a||_(a,J,l),m(m.P,h,Gt),R(h),m(m.P+m.F*jt,h,{set:Ut}),m(m.P+m.F*!d,h,Vt),g||a.toString==yt||(a.toString=yt),m(m.P+m.F*x(function(){new v(1).slice()}),h,{slice:Wt}),m(m.P+m.F*(x(function(){return[1,2].toLocaleString()!=new v([1,2]).toLocaleString()})||!x(function(){a.toLocaleString.call([1,2])})),h,{toLocaleString:Dt}),T[h]=d?s:y,g||d||_(a,bt,y)}}else t.exports=function(){}},function(t,n){var r={}.toString;t.exports=function(t){return r.call(t).slice(8,-1)}},function(t,n,r){var e=r(18),i=r(6).document,o=e(i)&&e(i.createElement);t.exports=function(t){return o?i.createElement(t):{}}},function(t,n,r){t.exports=!r(12)&&!r(20)(function(){return 7!=Object.defineProperty(r(59)("div"),"a",{get:function(){return 7}}).a})},function(t,n,r){"use strict";var x=r(23),m=r(54),S=r(66),w=r(13),_=r(36),O=r(98),E=r(38),M=r(104),P=r(16)("iterator"),j=!([].keys&&"next"in[].keys()),F="values",A=function(){return this};t.exports=function(t,n,r,e,i,o,u){O(r,n,e);var c,f,a,s=function(t){if(!j&&t in p)return p[t];switch(t){case"keys":case F:return function(){return new r(this,t)}}return function(){return new r(this,t)}},l=n+" Iterator",h=i==F,v=!1,p=t.prototype,d=p[P]||p["@@iterator"]||i&&p[i],y=d||s(i),g=i?h?s("entries"):y:void 0,b="Array"==n&&p.entries||d;if(b&&((a=M(b.call(new t)))!==Object.prototype&&a.next&&(E(a,l,!0),x||"function"==typeof a[P]||w(a,P,A))),h&&d&&d.name!==F&&(v=!0,y=function(){return d.call(this)}),x&&!u||!j&&!v&&p[P]||w(p,P,y),_[n]=y,_[l]=A,i)if(c={values:h?y:s(F),keys:o?y:s("keys"),entries:g},u)for(f in c)f in p||S(p,f,c[f]);else m(m.P+m.F*(j||v),n,c);return c}},function(t,n,e){var i=e(22),o=e(101),u=e(35),c=e(39)("IE_PROTO"),f=function(){},a="prototype",s=function(){var t,n=e(59)("iframe"),r=u.length;for(n.style.display="none",e(95).appendChild(n),n.src="javascript:",(t=n.contentWindow.document).open(),t.write("<script>document.F=Object<\/script>"),t.close(),s=t.F;r--;)delete s[a][u[r]];return s()};t.exports=Object.create||function(t,n){var r;return null!==t?(f[a]=i(t),r=new f,f[a]=null,r[c]=t):r=s(),void 0===n?r:o(r,n)}},function(t,n,r){var e=r(65),i=r(35).concat("length","prototype");n.f=Object.getOwnPropertyNames||function(t){return e(t,i)}},function(t,n){n.f=Object.getOwnPropertySymbols},function(t,n,r){var u=r(9),c=r(15),f=r(92)(!1),a=r(39)("IE_PROTO");t.exports=function(t,n){var r,e=c(t),i=0,o=[];for(r in e)r!=a&&u(e,r)&&o.push(r);for(;n.length>i;)u(e,r=n[i++])&&(~f(o,r)||o.push(r));return o}},function(t,n,r){t.exports=r(13)},function(t,n,r){var e=r(7)("unscopables"),i=Array.prototype;null==i[e]&&r(26)(i,e,{}),t.exports=function(t){i[e][t]=!0}},function(t,n){t.exports=!1},function(t,n,r){var e=r(79)("meta"),i=r(5),o=r(30),u=r(11).f,c=0,f=Object.isExtensible||function(){return!0},a=!r(4)(function(){return f(Object.preventExtensions({}))}),s=function(t){u(t,e,{value:{i:"O"+ ++c,w:{}}})},l=t.exports={KEY:e,NEED:!1,fastKey:function(t,n){if(!i(t))return"symbol"==typeof t?t:("string"==typeof t?"S":"P")+t;if(!o(t,e)){if(!f(t))return"F";if(!n)return"E";s(t)}return t[e].i},getWeak:function(t,n){if(!o(t,e)){if(!f(t))return!0;if(!n)return!1;s(t)}return t[e].w},onFreeze:function(t){return a&&l.NEED&&f(t)&&!o(t,e)&&s(t),t}}},function(t,n){t.exports=function(t,n,r,e){if(!(t instanceof n)||void 0!==e&&e in t)throw TypeError(r+": incorrect invocation!");return t}},function(t,n,r){var h=r(47),v=r(177),p=r(145),d=r(2),y=r(8),g=r(161),b={},x={};(n=t.exports=function(t,n,r,e,i){var o,u,c,f,a=i?function(){return t}:g(t),s=h(r,e,n?2:1),l=0;if("function"!=typeof a)throw TypeError(t+" is not iterable!");if(p(a)){for(o=y(t.length);l<o;l++)if((f=n?s(d(u=t[l])[0],u[1]):s(t[l]))===b||f===x)return f}else for(c=a.call(t);!(u=c.next()).done;)if((f=v(c,s,u.value,n))===b||f===x)return f}).BREAK=b,n.RETURN=x},function(t,n,e){var i=e(2),o=e(183),u=e(141),c=e(154)("IE_PROTO"),f=function(){},a="prototype",s=function(){var t,n=e(140)("iframe"),r=u.length;for(n.style.display="none",e(143).appendChild(n),n.src="javascript:",(t=n.contentWindow.document).open(),t.write("<script>document.F=Object<\/script>"),t.close(),s=t.F;r--;)delete s[a][u[r]];return s()};t.exports=Object.create||function(t,n){var r;return null!==t?(f[a]=i(t),r=new f,f[a]=null,r[c]=t):r=s(),void 0===n?r:o(r,n)}},function(t,n,r){var e=r(185),i=r(141).concat("length","prototype");n.f=Object.getOwnPropertyNames||function(t){return e(t,i)}},function(t,n,r){var e=r(185),i=r(141);t.exports=Object.keys||function(t){return e(t,i)}},function(t,n){t.exports=function(t,n){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:n}}},function(t,n,r){var i=r(27);t.exports=function(t,n,r){for(var e in n)i(t,e,n[e],r);return t}},function(t,n,r){"use strict";var e=r(3),i=r(11),o=r(10),u=r(7)("species");t.exports=function(t){var n=e[t];o&&n&&!n[u]&&i.f(n,u,{configurable:!0,get:function(){return this}})}},function(t,n,r){var e=r(49),i=Math.max,o=Math.min;t.exports=function(t,n){return(t=e(t))<0?i(t+n,0):o(t,n)}},function(t,n){var r=0,e=Math.random();t.exports=function(t){return"Symbol(".concat(void 0===t?"":t,")_",(++r+e).toString(36))}},function(t,n,r){var e=r(5);t.exports=function(t,n){if(!e(t)||t._t!==n)throw TypeError("Incompatible receiver, "+n+" required!");return t}},function(t,n,r){var i=r(45),o=r(7)("toStringTag"),u="Arguments"==i(function(){return arguments}());t.exports=function(t){var n,r,e;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(r=function(t,n){try{return t[n]}catch(t){}}(n=Object(t),o))?r:u?i(n):"Object"==(e=i(n))&&"function"==typeof n.callee?"Arguments":e}},function(t,n){t.exports={}},function(t,n,r){var e=r(11).f,i=r(30),o=r(7)("toStringTag");t.exports=function(t,n,r){t&&!i(t=r?t:t.prototype,o)&&e(t,o,{configurable:!0,value:n})}},function(t,n,r){var u=r(1),e=r(51),c=r(4),f=r(157),i="["+f+"]",o=RegExp("^"+i+i+"*"),a=RegExp(i+i+"*$"),s=function(t,n,r){var e={},i=c(function(){return!!f[t]()||"​"!="​"[t]()}),o=e[t]=i?n(l):f[t];r&&(e[r]=o),u(u.P+u.F*i,"String",e)},l=s.trim=function(t,n){return t=String(e(t)),1&n&&(t=t.replace(o,"")),2&n&&(t=t.replace(a,"")),t};t.exports=s},function(t,n,r){t.exports={default:r(88),__esModule:!0}},function(t,n,r){t.exports={default:r(89),__esModule:!0}},function(t,n,r){"use strict";function e(t){return t&&t.__esModule?t:{default:t}}n.__esModule=!0;var i=e(r(86)),o=e(r(85)),u="function"==typeof o.default&&"symbol"==typeof i.default?function(t){return typeof t}:function(t){return t&&"function"==typeof o.default&&t.constructor===o.default&&t!==o.default.prototype?"symbol":typeof t};n.default="function"==typeof o.default&&"symbol"===u(i.default)?function(t){return void 0===t?"undefined":u(t)}:function(t){return t&&"function"==typeof o.default&&t.constructor===o.default&&t!==o.default.prototype?"symbol":void 0===t?"undefined":u(t)}},function(t,n,r){r(111),r(109),r(112),r(113),t.exports=r(19).Symbol},function(t,n,r){r(110),r(114),t.exports=r(44).f("iterator")},function(t,n){t.exports=function(t){if("function"!=typeof t)throw TypeError(t+" is not a function!");return t}},function(t,n){t.exports=function(){}},function(t,n,r){var f=r(15),a=r(107),s=r(106);t.exports=function(c){return function(t,n,r){var e,i=f(t),o=a(i.length),u=s(r,o);if(c&&n!=n){for(;u<o;)if((e=i[u++])!=e)return!0}else for(;u<o;u++)if((c||u in i)&&i[u]===n)return c||u||0;return!c&&-1}}},function(t,n,r){var o=r(90);t.exports=function(e,i,t){if(o(e),void 0===i)return e;switch(t){case 1:return function(t){return e.call(i,t)};case 2:return function(t,n){return e.call(i,t,n)};case 3:return function(t,n,r){return e.call(i,t,n,r)}}return function(){return e.apply(i,arguments)}}},function(t,n,r){var c=r(29),f=r(64),a=r(37);t.exports=function(t){var n=c(t),r=f.f;if(r)for(var e,i=r(t),o=a.f,u=0;i.length>u;)o.call(t,e=i[u++])&&n.push(e);return n}},function(t,n,r){var e=r(6).document;t.exports=e&&e.documentElement},function(t,n,r){var e=r(58);t.exports=Object("z").propertyIsEnumerable(0)?Object:function(t){return"String"==e(t)?t.split(""):Object(t)}},function(t,n,r){var e=r(58);t.exports=Array.isArray||function(t){return"Array"==e(t)}},function(t,n,r){"use strict";var e=r(62),i=r(24),o=r(38),u={};r(13)(u,r(16)("iterator"),function(){return this}),t.exports=function(t,n,r){t.prototype=e(u,{next:i(1,r)}),o(t,n+" Iterator")}},function(t,n){t.exports=function(t,n){return{value:n,done:!!t}}},function(t,n,r){var e=r(25)("meta"),i=r(18),o=r(9),u=r(14).f,c=0,f=Object.isExtensible||function(){return!0},a=!r(20)(function(){return f(Object.preventExtensions({}))}),s=function(t){u(t,e,{value:{i:"O"+ ++c,w:{}}})},l=t.exports={KEY:e,NEED:!1,fastKey:function(t,n){if(!i(t))return"symbol"==typeof t?t:("string"==typeof t?"S":"P")+t;if(!o(t,e)){if(!f(t))return"F";if(!n)return"E";s(t)}return t[e].i},getWeak:function(t,n){if(!o(t,e)){if(!f(t))return!0;if(!n)return!1;s(t)}return t[e].w},onFreeze:function(t){return a&&l.NEED&&f(t)&&!o(t,e)&&s(t),t}}},function(t,n,r){var u=r(14),c=r(22),f=r(29);t.exports=r(12)?Object.defineProperties:function(t,n){c(t);for(var r,e=f(n),i=e.length,o=0;o<i;)u.f(t,r=e[o++],n[r]);return t}},function(t,n,r){var e=r(37),i=r(24),o=r(15),u=r(42),c=r(9),f=r(60),a=Object.getOwnPropertyDescriptor;n.f=r(12)?a:function(t,n){if(t=o(t),n=u(n,!0),f)try{return a(t,n)}catch(t){}if(c(t,n))return i(!e.f.call(t,n),t[n])}},function(t,n,r){var e=r(15),i=r(63).f,o={}.toString,u="object"==typeof window&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];t.exports.f=function(t){return u&&"[object Window]"==o.call(t)?function(t){try{return i(t)}catch(t){return u.slice()}}(t):i(e(t))}},function(t,n,r){var e=r(9),i=r(55),o=r(39)("IE_PROTO"),u=Object.prototype;t.exports=Object.getPrototypeOf||function(t){return t=i(t),e(t,o)?t[o]:"function"==typeof t.constructor&&t instanceof t.constructor?t.constructor.prototype:t instanceof Object?u:null}},function(t,n,r){var f=r(41),a=r(34);t.exports=function(c){return function(t,n){var r,e,i=String(a(t)),o=f(n),u=i.length;return o<0||u<=o?c?"":void 0:(r=i.charCodeAt(o))<55296||56319<r||o+1===u||(e=i.charCodeAt(o+1))<56320||57343<e?c?i.charAt(o):r:c?i.slice(o,o+2):e-56320+(r-55296<<10)+65536}}},function(t,n,r){var e=r(41),i=Math.max,o=Math.min;t.exports=function(t,n){return(t=e(t))<0?i(t+n,0):o(t,n)}},function(t,n,r){var e=r(41),i=Math.min;t.exports=function(t){return 0<t?i(e(t),9007199254740991):0}},function(t,n,r){"use strict";var e=r(91),i=r(99),o=r(36),u=r(15);t.exports=r(61)(Array,"Array",function(t,n){this._t=u(t),this._i=0,this._k=n},function(){var t=this._t,n=this._k,r=this._i++;return!t||r>=t.length?(this._t=void 0,i(1)):i(0,"keys"==n?r:"values"==n?t[r]:[r,t[r]])},"values"),o.Arguments=o.Array,e("keys"),e("values"),e("entries")},function(t,n){},function(t,n,r){"use strict";var e=r(105)(!0);r(61)(String,"String",function(t){this._t=String(t),this._i=0},function(){var t,n=this._t,r=this._i;return r>=n.length?{value:void 0,done:!0}:(t=e(n,r),this._i+=t.length,{value:t,done:!1})})},function(t,n,r){"use strict";var e=r(6),u=r(9),i=r(12),o=r(54),c=r(66),f=r(100).KEY,a=r(20),s=r(40),l=r(38),h=r(25),v=r(16),p=r(44),d=r(43),y=r(94),g=r(97),b=r(22),x=r(18),m=r(55),S=r(15),w=r(42),_=r(24),O=r(62),E=r(103),M=r(102),P=r(64),j=r(14),F=r(29),A=M.f,I=j.f,L=E.f,N=e.Symbol,T=e.JSON,k=T&&T.stringify,R="prototype",C=v("_hidden"),D=v("toPrimitive"),G={}.propertyIsEnumerable,W=s("symbol-registry"),U=s("symbols"),V=s("op-symbols"),B=Object[R],q="function"==typeof N&&!!P.f,z=e.QObject,H=!z||!z[R]||!z[R].findChild,K=i&&a(function(){return 7!=O(I({},"a",{get:function(){return I(this,"a",{value:7}).a}})).a})?function(t,n,r){var e=A(B,n);e&&delete B[n],I(t,n,r),e&&t!==B&&I(B,n,e)}:I,J=function(t){var n=U[t]=O(N[R]);return n._k=t,n},$=q&&"symbol"==typeof N.iterator?function(t){return"symbol"==typeof t}:function(t){return t instanceof N},Y=function(t,n,r){return t===B&&Y(V,n,r),b(t),n=w(n,!0),b(r),u(U,n)?(r.enumerable?(u(t,C)&&t[C][n]&&(t[C][n]=!1),r=O(r,{enumerable:_(0,!1)})):(u(t,C)||I(t,C,_(1,{})),t[C][n]=!0),K(t,n,r)):I(t,n,r)},X=function(t,n){b(t);for(var r,e=y(n=S(n)),i=0,o=e.length;i<o;)Y(t,r=e[i++],n[r]);return t},Q=function(t){var n=G.call(this,t=w(t,!0));return!(this===B&&u(U,t)&&!u(V,t))&&(!(n||!u(this,t)||!u(U,t)||u(this,C)&&this[C][t])||n)},Z=function(t,n){if(t=S(t),n=w(n,!0),t!==B||!u(U,n)||u(V,n)){var r=A(t,n);return!r||!u(U,n)||u(t,C)&&t[C][n]||(r.enumerable=!0),r}},tt=function(t){for(var n,r=L(S(t)),e=[],i=0;r.length>i;)u(U,n=r[i++])||n==C||n==f||e.push(n);return e},nt=function(t){for(var n,r=t===B,e=L(r?V:S(t)),i=[],o=0;e.length>o;)!u(U,n=e[o++])||r&&!u(B,n)||i.push(U[n]);return i};q||(c((N=function(){if(this instanceof N)throw TypeError("Symbol is not a constructor!");var n=h(0<arguments.length?arguments[0]:void 0),r=function(t){this===B&&r.call(V,t),u(this,C)&&u(this[C],n)&&(this[C][n]=!1),K(this,n,_(1,t))};return i&&H&&K(B,n,{configurable:!0,set:r}),J(n)})[R],"toString",function(){return this._k}),M.f=Z,j.f=Y,r(63).f=E.f=tt,r(37).f=Q,P.f=nt,i&&!r(23)&&c(B,"propertyIsEnumerable",Q,!0),p.f=function(t){return J(v(t))}),o(o.G+o.W+o.F*!q,{Symbol:N});for(var rt="hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables".split(","),et=0;rt.length>et;)v(rt[et++]);for(var it=F(v.store),ot=0;it.length>ot;)d(it[ot++]);o(o.S+o.F*!q,"Symbol",{for:function(t){return u(W,t+="")?W[t]:W[t]=N(t)},keyFor:function(t){if(!$(t))throw TypeError(t+" is not a symbol!");for(var n in W)if(W[n]===t)return n},useSetter:function(){H=!0},useSimple:function(){H=!1}}),o(o.S+o.F*!q,"Object",{create:function(t,n){return void 0===n?O(t):X(O(t),n)},defineProperty:Y,defineProperties:X,getOwnPropertyDescriptor:Z,getOwnPropertyNames:tt,getOwnPropertySymbols:nt});var ut=a(function(){P.f(1)});o(o.S+o.F*ut,"Object",{getOwnPropertySymbols:function(t){return P.f(m(t))}}),T&&o(o.S+o.F*(!q||a(function(){var t=N();return"[null]"!=k([t])||"{}"!=k({a:t})||"{}"!=k(Object(t))})),"JSON",{stringify:function(t){for(var n,r,e=[t],i=1;arguments.length>i;)e.push(arguments[i++]);if(r=n=e[1],(x(n)||void 0!==t)&&!$(t))return g(n)||(n=function(t,n){if("function"==typeof r&&(n=r.call(this,t,n)),!$(n))return n}),e[1]=n,k.apply(T,e)}}),N[R][D]||r(13)(N[R],D,N[R].valueOf),l(N,"Symbol"),l(Math,"Math",!0),l(e.JSON,"JSON",!0)},function(t,n,r){r(43)("asyncIterator")},function(t,n,r){r(43)("observable")},function(t,n,r){r(108);for(var e=r(6),i=r(13),o=r(36),u=r(16)("toStringTag"),c="CSSRuleList,CSSStyleDeclaration,CSSValueList,ClientRectList,DOMRectList,DOMStringList,DOMTokenList,DataTransferItemList,FileList,HTMLAllCollection,HTMLCollection,HTMLFormElement,HTMLSelectElement,MediaList,MimeTypeArray,NamedNodeMap,NodeList,PaintRequestList,Plugin,PluginArray,SVGLengthList,SVGNumberList,SVGPathSegList,SVGPointList,SVGStringList,SVGTransformList,SourceBufferList,StyleSheetList,TextTrackCueList,TextTrackList,TouchList".split(","),f=0;f<c.length;f++){var a=c[f],s=e[a],l=s&&s.prototype;l&&!l[u]&&i(l,u,a),o[a]=o.Array}},function(t,n,r){"use strict";var e=r(2);t.exports=function(){var t=e(this),n="";return t.global&&(n+="g"),t.ignoreCase&&(n+="i"),t.multiline&&(n+="m"),t.unicode&&(n+="u"),t.sticky&&(n+="y"),n}},function(t,n,r){var e=r(45);t.exports=Object("z").propertyIsEnumerable(0)?Object:function(t){return"String"==e(t)?t.split(""):Object(t)}},function(t,n){n.f={}.propertyIsEnumerable},function(t,n,r){var e=r(46),i=r(3),o="__core-js_shared__",u=i[o]||(i[o]={});(t.exports=function(t,n){return u[t]||(u[t]=void 0!==n?n:{})})("versions",[]).push({version:e.version,mode:r(68)?"pure":"global",copyright:"© 2019 Denis Pushkarev (zloirock.ru)"})},function(t,n,r){var i=r(2),o=r(21),u=r(7)("species");t.exports=function(t,n){var r,e=i(t).constructor;return void 0===e||null==(r=i(e)[u])?n:o(r)}},function(t,n,r){var f=r(33),a=r(8),s=r(78);t.exports=function(c){return function(t,n,r){var e,i=f(t),o=a(i.length),u=s(r,o);if(c&&n!=n){for(;u<o;)if((e=i[u++])!=e)return!0}else for(;u<o;u++)if((c||u in i)&&i[u]===n)return c||u||0;return!c&&-1}}},function(t,n,r){"use strict";var g=r(3),b=r(1),x=r(27),m=r(76),S=r(69),w=r(71),_=r(70),O=r(5),E=r(4),M=r(125),P=r(83),j=r(144);t.exports=function(e,t,n,r,i,o){var u=g[e],c=u,f=i?"set":"add",a=c&&c.prototype,s={},l=function(t){var r=a[t];x(a,t,"delete"==t?function(t){return!(o&&!O(t))&&r.call(this,0===t?0:t)}:"has"==t?function(t){return!(o&&!O(t))&&r.call(this,0===t?0:t)}:"get"==t?function(t){return o&&!O(t)?void 0:r.call(this,0===t?0:t)}:"add"==t?function(t){return r.call(this,0===t?0:t),this}:function(t,n){return r.call(this,0===t?0:t,n),this})};if("function"==typeof c&&(o||a.forEach&&!E(function(){(new c).entries().next()}))){var h=new c,v=h[f](o?{}:-0,1)!=h,p=E(function(){h.has(1)}),d=M(function(t){new c(t)}),y=!o&&E(function(){for(var t=new c,n=5;n--;)t[f](n,n);return!t.has(-0)});d||(((c=t(function(t,n){_(t,c,e);var r=j(new u,t,c);return null!=n&&w(n,i,r[f],r),r})).prototype=a).constructor=c),(p||y)&&(l("delete"),l("has"),i&&l("get")),(y||v)&&l(f),o&&a.clear&&delete a.clear}else c=r.getConstructor(t,e,i,f),m(c.prototype,n),S.NEED=!0;return P(c,e),s[e]=c,b(b.G+b.W+b.F*(c!=u),s),o||r.setStrong(c,e,i),c}},function(t,n,r){"use strict";r(197);var s=r(27),l=r(26),h=r(4),v=r(51),p=r(7),d=r(152),y=p("species"),g=!h(function(){var t=/./;return t.exec=function(){var t=[];return t.groups={a:"7"},t},"7"!=="".replace(t,"$<a>")}),b=function(){var t=/(?:)/,n=t.exec;t.exec=function(){return n.apply(this,arguments)};var r="ab".split(t);return 2===r.length&&"a"===r[0]&&"b"===r[1]}();t.exports=function(r,t,n){var e=p(r),o=!h(function(){var t={};return t[e]=function(){return 7},7!=""[r](t)}),i=o?!h(function(){var t=!1,n=/a/;return n.exec=function(){return t=!0,null},"split"===r&&(n.constructor={},n.constructor[y]=function(){return n}),n[e](""),!t}):void 0;if(!o||!i||"replace"===r&&!g||"split"===r&&!b){var u=/./[e],c=n(v,e,""[r],function(t,n,r,e,i){return n.exec===d?o&&!i?{done:!0,value:u.call(n,r,e)}:{done:!0,value:t.call(r,n,e)}:{done:!1}}),f=c[0],a=c[1];s(String.prototype,r,f),l(RegExp.prototype,e,2==t?function(t,n){return a.call(t,this,n)}:function(t){return a.call(t,this)})}}},function(t,n,r){var e=r(45);t.exports=Array.isArray||function(t){return"Array"==e(t)}},function(t,n,r){var e=r(5),i=r(45),o=r(7)("match");t.exports=function(t){var n;return e(t)&&(void 0!==(n=t[o])?!!n:"RegExp"==i(t))}},function(t,n,r){var o=r(7)("iterator"),u=!1;try{var e=[7][o]();e.return=function(){u=!0},Array.from(e,function(){throw 2})}catch(t){}t.exports=function(t,n){if(!n&&!u)return!1;var r=!1;try{var e=[7],i=e[o]();i.next=function(){return{done:r=!0}},e[o]=function(){return i},t(e)}catch(t){}return r}},function(t,n,r){"use strict";t.exports=r(68)||!r(4)(function(){var t=Math.random();__defineSetter__.call(null,t,function(){}),delete r(3)[t]})},function(t,n){n.f=Object.getOwnPropertySymbols},function(t,n,r){"use strict";var i=r(81),o=RegExp.prototype.exec;t.exports=function(t,n){var r=t.exec;if("function"==typeof r){var e=r.call(t,n);if("object"!=typeof e)throw new TypeError("RegExp exec method returned something other than an Object or null");return e}if("RegExp"!==i(t))throw new TypeError("RegExp#exec called on incompatible receiver");return o.call(t,n)}},function(t,n,r){"use strict";var e=r(1),u=r(21),c=r(47),f=r(71);t.exports=function(t){e(e.S,t,{from:function(t){var n,r,e,i,o=arguments[1];return u(this),(n=void 0!==o)&&u(o),null==t?new this:(r=[],n?(e=0,i=c(o,arguments[2],2),f(t,!1,function(t){r.push(i(t,e++))})):f(t,!1,r.push,r),new this(r))}})}},function(t,n,r){"use strict";var e=r(1);t.exports=function(t){e(e.S,t,{of:function(){for(var t=arguments.length,n=new Array(t);t--;)n[t]=arguments[t];return new this(n)}})}},function(t,n,r){var f=r(49),a=r(51);t.exports=function(c){return function(t,n){var r,e,i=String(a(t)),o=f(n),u=i.length;return o<0||u<=o?c?"":void 0:(r=i.charCodeAt(o))<55296||56319<r||o+1===u||(e=i.charCodeAt(o+1))<56320||57343<e?c?i.charAt(o):r:c?i.slice(o,o+2):e-56320+(r-55296<<10)+65536}}},function(t,n,r){for(var e,i=r(3),o=r(26),u=r(79),c=u("typed_array"),f=u("view"),a=!(!i.ArrayBuffer||!i.DataView),s=a,l=0,h="Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array".split(",");l<9;)(e=i[h[l++]])?(o(e.prototype,c,!0),o(e.prototype,f,!0)):s=!1;t.exports={ABV:a,CONSTR:s,TYPED:c,VIEW:f}},function(t,n,r){var e=r(3).navigator;t.exports=e&&e.userAgent||""},function(t,n){"use strict";var r,e={versions:(r=window.navigator.userAgent,{trident:-1<r.indexOf("Trident"),presto:-1<r.indexOf("Presto"),webKit:-1<r.indexOf("AppleWebKit"),gecko:-1<r.indexOf("Gecko")&&-1==r.indexOf("KHTML"),mobile:!!r.match(/AppleWebKit.*Mobile.*/),ios:!!r.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),android:-1<r.indexOf("Android")||-1<r.indexOf("Linux"),iPhone:-1<r.indexOf("iPhone")||-1<r.indexOf("Mac"),iPad:-1<r.indexOf("iPad"),webApp:-1==r.indexOf("Safari"),weixin:-1==r.indexOf("MicroMessenger")})};t.exports=e},function(t,n,r){"use strict";var e,i=r(87),l=(e=i)&&e.__esModule?e:{default:e},h=function(){function n(t,n,r){return n||r?String.fromCharCode(n||r):o[t]||t}function r(t){return s[t]}var e=/&quot;|&lt;|&gt;|&amp;|&nbsp;|&apos;|&#(\d+);|&#(\d+)/g,i=/['<> "&]/g,o={"&quot;":'"',"&lt;":"<","&gt;":">","&amp;":"&","&nbsp;":" "},u=/\u00a0/g,c=/<br\s*\/?>/gi,f=/\r?\n/g,a=/\s/g,s={};for(var t in o)s[o[t]]=t;return o["&apos;"]="'",s["'"]="&#39;",{encode:function(t){return t?(""+t).replace(i,r).replace(f,"<br/>").replace(a,"&nbsp;"):""},decode:function(t){return t?(""+t).replace(c,"\n").replace(e,n).replace(u," "):""},encodeBase16:function(t){if(!t)return t;for(var n=[],r=0,e=(t+="").length;r<e;r++)n.push(t.charCodeAt(r).toString(16).toUpperCase());return n.join("")},encodeBase16forJSON:function(t){if(!t)return t;for(var n=[],r=0,e=(t=t.replace(/[\u4E00-\u9FBF]/gi,function(t){return escape(t).replace("%u","\\u")})).length;r<e;r++)n.push(t.charCodeAt(r).toString(16).toUpperCase());return n.join("")},decodeBase16:function(t){if(!t)return t;for(var n=[],r=0,e=(t+="").length;r<e;r+=2)n.push(String.fromCharCode("0x"+t.slice(r,r+2)));return n.join("")},encodeObject:function(t){if(t instanceof Array)for(var n=0,r=t.length;n<r;n++)t[n]=h.encodeObject(t[n]);else if("object"==(void 0===t?"undefined":(0,l.default)(t)))for(var e in t)t[e]=h.encodeObject(t[e]);else if("string"==typeof t)return h.encode(t);return t},loadScript:function(t){var n=document.createElement("script");document.getElementsByTagName("body")[0].appendChild(n),n.setAttribute("src",t)},addLoadEvent:function(t){var n=window.onload;"function"!=typeof window.onload?window.onload=t:window.onload=function(){n(),t()}}}}();t.exports=h},function(t,n,r){"use strict";var e=r(131)(!0);t.exports=function(t,n,r){return n+(r?e(t,n).length:1)}},function(t,n,r){"use strict";var c=r(17),f=r(78),a=r(8);t.exports=function(t){for(var n=c(this),r=a(n.length),e=arguments.length,i=f(1<e?arguments[1]:void 0,r),o=2<e?arguments[2]:void 0,u=void 0===o?r:f(o,r);i<u;)n[i++]=t;return n}},function(t,n,r){var e=r(217);t.exports=function(t,n){return new(e(t))(n)}},function(t,n,r){"use strict";var e=r(11),i=r(75);t.exports=function(t,n,r){n in t?e.f(t,n,i(0,r)):t[n]=r}},function(t,n,r){var e=r(5),i=r(3).document,o=e(i)&&e(i.createElement);t.exports=function(t){return o?i.createElement(t):{}}},function(t,n){t.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},function(t,n,r){var e=r(7)("match");t.exports=function(n){var r=/./;try{"/./"[n](r)}catch(t){try{return r[e]=!1,!"/./"[n](r)}catch(n){}}return!0}},function(t,n,r){var e=r(3).document;t.exports=e&&e.documentElement},function(t,n,r){var o=r(5),u=r(153).set;t.exports=function(t,n,r){var e,i=n.constructor;return i!==r&&"function"==typeof i&&(e=i.prototype)!==r.prototype&&o(e)&&u&&u(t,e),t}},function(t,n,r){var e=r(82),i=r(7)("iterator"),o=Array.prototype;t.exports=function(t){return void 0!==t&&(e.Array===t||o[i]===t)}},function(t,n,r){"use strict";var e=r(72),i=r(75),o=r(83),u={};r(26)(u,r(7)("iterator"),function(){return this}),t.exports=function(t,n,r){t.prototype=e(u,{next:i(1,r)}),o(t,n+" Iterator")}},function(t,n,r){"use strict";var x=r(68),m=r(1),S=r(27),w=r(26),_=r(82),O=r(146),E=r(83),M=r(32),P=r(7)("iterator"),j=!([].keys&&"next"in[].keys()),F="values",A=function(){return this};t.exports=function(t,n,r,e,i,o,u){O(r,n,e);var c,f,a,s=function(t){if(!j&&t in p)return p[t];switch(t){case"keys":case F:return function(){return new r(this,t)}}return function(){return new r(this,t)}},l=n+" Iterator",h=i==F,v=!1,p=t.prototype,d=p[P]||p["@@iterator"]||i&&p[i],y=d||s(i),g=i?h?s("entries"):y:void 0,b="Array"==n&&p.entries||d;if(b&&((a=M(b.call(new t)))!==Object.prototype&&a.next&&(E(a,l,!0),x||"function"==typeof a[P]||w(a,P,A))),h&&d&&d.name!==F&&(v=!0,y=function(){return d.call(this)}),x&&!u||!j&&!v&&p[P]||w(p,P,y),_[n]=y,_[l]=A,i)if(c={values:h?y:s(F),keys:o?y:s("keys"),entries:g},u)for(f in c)f in p||S(p,f,c[f]);else m(m.P+m.F*(j||v),n,c);return c}},function(t,n){var r=Math.expm1;t.exports=!r||22025.465794806718<r(10)||r(10)<22025.465794806718||-2e-17!=r(-2e-17)?function(t){return 0==(t=+t)?t:-1e-6<t&&t<1e-6?t+t*t/2:Math.exp(t)-1}:r},function(t,n){t.exports=Math.sign||function(t){return 0==(t=+t)||t!=t?t:t<0?-1:1}},function(t,n,r){var c=r(3),f=r(158).set,a=c.MutationObserver||c.WebKitMutationObserver,s=c.process,l=c.Promise,h="process"==r(45)(s);t.exports=function(){var r,e,i,t=function(){var t,n;for(h&&(t=s.domain)&&t.exit();r;){n=r.fn,r=r.next;try{n()}catch(t){throw r?i():e=void 0,t}}e=void 0,t&&t.enter()};if(h)i=function(){s.nextTick(t)};else if(!a||c.navigator&&c.navigator.standalone)if(l&&l.resolve){var n=l.resolve(void 0);i=function(){n.then(t)}}else i=function(){f.call(c,t)};else{var o=!0,u=document.createTextNode("");new a(t).observe(u,{characterData:!0}),i=function(){u.data=o=!o}}return function(t){var n={fn:t,next:void 0};e&&(e.next=n),r||(r=n,i()),e=n}}},function(t,n,r){"use strict";function e(t){var r,e;this.promise=new t(function(t,n){if(void 0!==r||void 0!==e)throw TypeError("Bad Promise constructor");r=t,e=n}),this.resolve=i(r),this.reject=i(e)}var i=r(21);t.exports.f=function(t){return new e(t)}},function(t,n,r){"use strict";var e,i,u=r(115),c=RegExp.prototype.exec,f=String.prototype.replace,o=c,a="lastIndex",s=(e=/a/,i=/b*/g,c.call(e,"a"),c.call(i,"a"),0!==e[a]||0!==i[a]),l=void 0!==/()??/.exec("")[1];(s||l)&&(o=function(t){var n,r,e,i,o=this;return l&&(r=new RegExp("^"+o.source+"$(?!\\s)",u.call(o))),s&&(n=o[a]),e=c.call(o,t),s&&e&&(o[a]=o.global?e.index+e[0].length:n),l&&e&&1<e.length&&f.call(e[0],r,function(){for(i=1;i<arguments.length-2;i++)void 0===arguments[i]&&(e[i]=void 0)}),e}),t.exports=o},function(t,n,i){var r=i(5),e=i(2),o=function(t,n){if(e(t),!r(n)&&null!==n)throw TypeError(n+": can't set as prototype!")};t.exports={set:Object.setPrototypeOf||("__proto__"in{}?function(t,r,e){try{(e=i(47)(Function.call,i(31).f(Object.prototype,"__proto__").set,2))(t,[]),r=!(t instanceof Array)}catch(t){r=!0}return function(t,n){return o(t,n),r?t.__proto__=n:e(t,n),t}}({},!1):void 0),check:o}},function(t,n,r){var e=r(118)("keys"),i=r(79);t.exports=function(t){return e[t]||(e[t]=i(t))}},function(t,n,r){var e=r(124),i=r(51);t.exports=function(t,n,r){if(e(n))throw TypeError("String#"+r+" doesn't accept regex!");return String(i(t))}},function(t,n,r){"use strict";var i=r(49),o=r(51);t.exports=function(t){var n=String(o(this)),r="",e=i(t);if(e<0||e==1/0)throw RangeError("Count can't be negative");for(;0<e;(e>>>=1)&&(n+=n))1&e&&(r+=n);return r}},function(t,n){t.exports="\t\n\v\f\r   ᠎             　\u2028\u2029\ufeff"},function(t,n,r){var e,i,o,u=r(47),c=r(175),f=r(143),a=r(140),s=r(3),l=s.process,h=s.setImmediate,v=s.clearImmediate,p=s.MessageChannel,d=s.Dispatch,y=0,g={},b="onreadystatechange",x=function(){var t=+this;if(g.hasOwnProperty(t)){var n=g[t];delete g[t],n()}},m=function(t){x.call(t.data)};h&&v||(h=function(t){for(var n=[],r=1;arguments.length>r;)n.push(arguments[r++]);return g[++y]=function(){c("function"==typeof t?t:Function(t),n)},e(y),y},v=function(t){delete g[t]},"process"==r(45)(l)?e=function(t){l.nextTick(u(x,t,1))}:d&&d.now?e=function(t){d.now(u(x,t,1))}:p?(o=(i=new p).port2,i.port1.onmessage=m,e=u(o.postMessage,o,1)):s.addEventListener&&"function"==typeof postMessage&&!s.importScripts?(e=function(t){s.postMessage(t+"","*")},s.addEventListener("message",m,!1)):e=b in a("script")?function(t){f.appendChild(a("script"))[b]=function(){f.removeChild(this),x.call(t)}}:function(t){setTimeout(u(x,t,1),0)}),t.exports={set:h,clear:v}},function(t,n,r){"use strict";function e(t,n,r){var e,i,o,u=new Array(r),c=8*r-n-1,f=(1<<c)-1,a=f>>1,s=23===n?W(2,-24)-W(2,-77):0,l=0,h=t<0||0===t&&1/t<0?1:0;for((t=G(t))!=t||t===C?(i=t!=t?1:0,e=f):(e=U(V(t)/B),t*(o=W(2,-e))<1&&(e--,o*=2),2<=(t+=1<=e+a?s/o:s*W(2,1-a))*o&&(e++,o/=2),f<=e+a?(i=0,e=f):1<=e+a?(i=(t*o-1)*W(2,n),e+=a):(i=t*W(2,a-1)*W(2,n),e=0));8<=n;u[l++]=255&i,i/=256,n-=8);for(e=e<<n|i,c+=n;0<c;u[l++]=255&e,e/=256,c-=8);return u[--l]|=128*h,u}function i(t,n,r){var e,i=8*r-n-1,o=(1<<i)-1,u=o>>1,c=i-7,f=r-1,a=t[f--],s=127&a;for(a>>=7;0<c;s=256*s+t[f],f--,c-=8);for(e=s&(1<<-c)-1,s>>=-c,c+=n;0<c;e=256*e+t[f],f--,c-=8);if(0===s)s=1-u;else{if(s===o)return e?NaN:a?-C:C;e+=W(2,n),s-=u}return(a?-1:1)*e*W(2,s-n)}function o(t){return t[3]<<24|t[2]<<16|t[1]<<8|t[0]}function u(t){return[255&t]}function c(t){return[255&t,t>>8&255]}function f(t){return[255&t,t>>8&255,t>>16&255,t>>24&255]}function a(t){return e(t,52,8)}function s(t){return e(t,23,4)}function l(t,n,r){M(t[I],n,{get:function(){return this[r]}})}function h(t,n,r,e){var i=O(+r);if(i+n>t[K])throw R(L);var o=t[H]._b,u=i+t[J],c=o.slice(u,u+n);return e?c:c.reverse()}function v(t,n,r,e,i,o){var u=O(+r);if(u+n>t[K])throw R(L);for(var c=t[H]._b,f=u+t[J],a=e(+i),s=0;s<n;s++)c[f+s]=a[o?s:n-s-1]}var p=r(3),d=r(10),y=r(68),g=r(132),b=r(26),x=r(76),m=r(4),S=r(70),w=r(49),_=r(8),O=r(194),E=r(73).f,M=r(11).f,P=r(137),j=r(83),F="ArrayBuffer",A="DataView",I="prototype",L="Wrong index!",N=p[F],T=p[A],k=p.Math,R=p.RangeError,C=p.Infinity,D=N,G=k.abs,W=k.pow,U=k.floor,V=k.log,B=k.LN2,q="byteLength",z="byteOffset",H=d?"_b":"buffer",K=d?"_l":q,J=d?"_o":z;if(g.ABV){if(!m(function(){N(1)})||!m(function(){new N(-1)})||m(function(){return new N,new N(1.5),new N(NaN),N.name!=F})){for(var $,Y=(N=function(t){return S(this,N),new D(O(t))})[I]=D[I],X=E(D),Q=0;X.length>Q;)($=X[Q++])in N||b(N,$,D[$]);y||(Y.constructor=N)}var Z=new T(new N(2)),tt=T[I].setInt8;Z.setInt8(0,2147483648),Z.setInt8(1,2147483649),!Z.getInt8(0)&&Z.getInt8(1)||x(T[I],{setInt8:function(t,n){tt.call(this,t,n<<24>>24)},setUint8:function(t,n){tt.call(this,t,n<<24>>24)}},!0)}else N=function(t){S(this,N,F);var n=O(t);this._b=P.call(new Array(n),0),this[K]=n},T=function(t,n,r){S(this,T,A),S(t,N,A);var e=t[K],i=w(n);if(i<0||e<i)throw R("Wrong offset!");if(e<i+(r=void 0===r?e-i:_(r)))throw R("Wrong length!");this[H]=t,this[J]=i,this[K]=r},d&&(l(N,q,"_l"),l(T,"buffer","_b"),l(T,q,"_l"),l(T,z,"_o")),x(T[I],{getInt8:function(t){return h(this,1,t)[0]<<24>>24},getUint8:function(t){return h(this,1,t)[0]},getInt16:function(t){var n=h(this,2,t,arguments[1]);return(n[1]<<8|n[0])<<16>>16},getUint16:function(t){var n=h(this,2,t,arguments[1]);return n[1]<<8|n[0]},getInt32:function(t){return o(h(this,4,t,arguments[1]))},getUint32:function(t){return o(h(this,4,t,arguments[1]))>>>0},getFloat32:function(t){return i(h(this,4,t,arguments[1]),23,4)},getFloat64:function(t){return i(h(this,8,t,arguments[1]),52,8)},setInt8:function(t,n){v(this,1,t,u,n)},setUint8:function(t,n){v(this,1,t,u,n)},setInt16:function(t,n){v(this,2,t,c,n,arguments[2])},setUint16:function(t,n){v(this,2,t,c,n,arguments[2])},setInt32:function(t,n){v(this,4,t,f,n,arguments[2])},setUint32:function(t,n){v(this,4,t,f,n,arguments[2])},setFloat32:function(t,n){v(this,4,t,s,n,arguments[2])},setFloat64:function(t,n){v(this,8,t,a,n,arguments[2])}});j(N,F),j(T,A),b(T[I],g.VIEW,!0),n[F]=N,n[A]=T},function(t,n,r){var e=r(3),i=r(46),o=r(68),u=r(195),c=r(11).f;t.exports=function(t){var n=i.Symbol||(i.Symbol=o?{}:e.Symbol||{});"_"==t.charAt(0)||t in n||c(n,t,{value:u.f(t)})}},function(t,n,r){var e=r(81),i=r(7)("iterator"),o=r(82);t.exports=r(46).getIteratorMethod=function(t){if(null!=t)return t[i]||t["@@iterator"]||o[e(t)]}},function(t,n,r){"use strict";var e=r(67),i=r(178),o=r(82),u=r(33);t.exports=r(147)(Array,"Array",function(t,n){this._t=u(t),this._i=0,this._k=n},function(){var t=this._t,n=this._k,r=this._i++;return!t||r>=t.length?(this._t=void 0,i(1)):i(0,"keys"==n?r:"values"==n?t[r]:[r,t[r]])},"values"),o.Arguments=o.Array,e("keys"),e("values"),e("entries")},function(t,n){t.exports=function(t,n){t.classList?t.classList.add(n):t.className+=" "+n}},function(t,n){t.exports=function(t,n){if(t.classList)t.classList.remove(n);else{var r=new RegExp("(^|\\b)"+n.split(" ").join("|")+"(\\b|$)","gi");t.className=t.className.replace(r," ")}}},function(t,n,r){var e=r(45);t.exports=function(t,n){if("number"!=typeof t&&"Number"!=e(t))throw TypeError(n);return+t}},function(t,n,r){"use strict";var a=r(17),s=r(78),l=r(8);t.exports=[].copyWithin||function(t,n){var r=a(this),e=l(r.length),i=s(t,e),o=s(n,e),u=2<arguments.length?arguments[2]:void 0,c=Math.min((void 0===u?e:s(u,e))-o,e-i),f=1;for(o<i&&i<o+c&&(f=-1,o+=c-1,i+=c-1);0<c--;)o in r?r[i]=r[o]:delete r[i],i+=f,o+=f;return r}},function(t,n,r){var e=r(71);t.exports=function(t,n){var r=[];return e(t,!1,r.push,r,n),r}},function(t,n,r){var s=r(21),l=r(17),h=r(116),v=r(8);t.exports=function(t,n,r,e,i){s(n);var o=l(t),u=h(o),c=v(o.length),f=i?c-1:0,a=i?-1:1;if(r<2)for(;;){if(f in u){e=u[f],f+=a;break}if(f+=a,i?f<0:c<=f)throw TypeError("Reduce of empty array with no initial value")}for(;i?0<=f:f<c;f+=a)f in u&&(e=n(e,u[f],f,o));return e}},function(t,n,r){"use strict";var o=r(21),u=r(5),c=r(175),f=[].slice,a={};t.exports=Function.bind||function(n){var r=o(this),e=f.call(arguments,1),i=function(){var t=e.concat(f.call(arguments));return this instanceof i?function(t,n,r){if(!(n in a)){for(var e=[],i=0;i<n;i++)e[i]="a["+i+"]";a[n]=Function("F,a","return new F("+e.join(",")+")")}return a[n](t,r)}(r,t.length,t):c(r,t,n)};return u(r.prototype)&&(i.prototype=r.prototype),i}},function(t,n,r){"use strict";var u=r(11).f,c=r(72),f=r(76),a=r(47),s=r(70),l=r(71),e=r(147),i=r(178),o=r(77),h=r(10),v=r(69).fastKey,p=r(80),d=h?"_s":"size",y=function(t,n){var r,e=v(n);if("F"!==e)return t._i[e];for(r=t._f;r;r=r.n)if(r.k==n)return r};t.exports={getConstructor:function(t,o,r,e){var i=t(function(t,n){s(t,i,o,"_i"),t._t=o,t._i=c(null),t._f=void 0,t._l=void 0,t[d]=0,null!=n&&l(n,r,t[e],t)});return f(i.prototype,{clear:function(){for(var t=p(this,o),n=t._i,r=t._f;r;r=r.n)r.r=!0,r.p&&(r.p=r.p.n=void 0),delete n[r.i];t._f=t._l=void 0,t[d]=0},delete:function(t){var n=p(this,o),r=y(n,t);if(r){var e=r.n,i=r.p;delete n._i[r.i],r.r=!0,i&&(i.n=e),e&&(e.p=i),n._f==r&&(n._f=e),n._l==r&&(n._l=i),n[d]--}return!!r},forEach:function(t){p(this,o);for(var n,r=a(t,1<arguments.length?arguments[1]:void 0,3);n=n?n.n:this._f;)for(r(n.v,n.k,this);n&&n.r;)n=n.p},has:function(t){return!!y(p(this,o),t)}}),h&&u(i.prototype,"size",{get:function(){return p(this,o)[d]}}),i},def:function(t,n,r){var e,i,o=y(t,n);return o?o.v=r:(t._l=o={i:i=v(n,!0),k:n,v:r,p:e=t._l,n:void 0,r:!1},t._f||(t._f=o),e&&(e.n=o),t[d]++,"F"!==i&&(t._i[i]=o)),t},getEntry:y,setStrong:function(t,r,n){e(t,r,function(t,n){this._t=p(t,r),this._k=n,this._l=void 0},function(){for(var t=this,n=t._k,r=t._l;r&&r.r;)r=r.p;return t._t&&(t._l=r=r?r.n:t._t._f)?i(0,"keys"==n?r.k:"values"==n?r.v:[r.k,r.v]):(t._t=void 0,i(1))},n?"entries":"values",!n,!0),o(r)}}},function(t,n,r){var e=r(81),i=r(167);t.exports=function(t){return function(){if(e(this)!=t)throw TypeError(t+"#toJSON isn't generic");return i(this)}}},function(t,n,r){"use strict";var u=r(76),c=r(69).getWeak,i=r(2),f=r(5),a=r(70),s=r(71),e=r(50),l=r(30),h=r(80),o=e(5),v=e(6),p=0,d=function(t){return t._l||(t._l=new y)},y=function(){this.a=[]},g=function(t,n){return o(t.a,function(t){return t[0]===n})};y.prototype={get:function(t){var n=g(this,t);if(n)return n[1]},has:function(t){return!!g(this,t)},set:function(t,n){var r=g(this,t);r?r[1]=n:this.a.push([t,n])},delete:function(n){var t=v(this.a,function(t){return t[0]===n});return~t&&this.a.splice(t,1),!!~t}},t.exports={getConstructor:function(t,r,e,i){var o=t(function(t,n){a(t,o,r,"_i"),t._t=r,t._i=p++,t._l=void 0,null!=n&&s(n,e,t[i],t)});return u(o.prototype,{delete:function(t){if(!f(t))return!1;var n=c(t);return!0===n?d(h(this,r)).delete(t):n&&l(n,this._i)&&delete n[this._i]},has:function(t){if(!f(t))return!1;var n=c(t);return!0===n?d(h(this,r)).has(t):n&&l(n,this._i)}}),o},def:function(t,n,r){var e=c(i(n),!0);return!0===e?d(t).set(n,r):e[t._i]=r,t},ufstore:d}},function(t,n,r){"use strict";var p=r(123),d=r(5),y=r(8),g=r(47),b=r(7)("isConcatSpreadable");t.exports=function t(n,r,e,i,o,u,c,f){for(var a,s,l=o,h=0,v=!!c&&g(c,f,3);h<i;){if(h in e){if(a=v?v(e[h],h,r):e[h],s=!1,d(a)&&(s=void 0!==(s=a[b])?!!s:p(a)),s&&0<u)l=t(n,r,a,y(a.length),l,u-1)-1;else{if(9007199254740991<=l)throw TypeError();n[l]=a}l++}h++}return l}},function(t,n,r){t.exports=!r(10)&&!r(4)(function(){return 7!=Object.defineProperty(r(140)("div"),"a",{get:function(){return 7}}).a})},function(t,n){t.exports=function(t,n,r){var e=void 0===r;switch(n.length){case 0:return e?t():t.call(r);case 1:return e?t(n[0]):t.call(r,n[0]);case 2:return e?t(n[0],n[1]):t.call(r,n[0],n[1]);case 3:return e?t(n[0],n[1],n[2]):t.call(r,n[0],n[1],n[2]);case 4:return e?t(n[0],n[1],n[2],n[3]):t.call(r,n[0],n[1],n[2],n[3])}return t.apply(r,n)}},function(t,n,r){var e=r(5),i=Math.floor;t.exports=function(t){return!e(t)&&isFinite(t)&&i(t)===t}},function(t,n,r){var o=r(2);t.exports=function(t,n,r,e){try{return e?n(o(r)[0],r[1]):n(r)}catch(n){var i=t.return;throw void 0!==i&&o(i.call(t)),n}}},function(t,n){t.exports=function(t,n){return{value:n,done:!!t}}},function(t,n,r){var o=r(149),e=Math.pow,u=e(2,-52),c=e(2,-23),f=e(2,127)*(2-c),a=e(2,-126);t.exports=Math.fround||function(t){var n,r,e=Math.abs(t),i=o(t);return e<a?i*(e/a/c+1/u-1/u)*a*c:f<(r=(n=(1+c/u)*e)-(n-e))||r!=r?i*(1/0):i*r}},function(t,n){t.exports=Math.log1p||function(t){return-1e-8<(t=+t)&&t<1e-8?t-t*t/2:Math.log(1+t)}},function(t,n){t.exports=Math.scale||function(t,n,r,e,i){return 0===arguments.length||t!=t||n!=n||r!=r||e!=e||i!=i?NaN:t===1/0||t===-1/0?t:(t-n)*(i-e)/(r-n)+e}},function(t,n,r){"use strict";var h=r(10),v=r(74),p=r(127),d=r(117),y=r(17),g=r(116),i=Object.assign;t.exports=!i||r(4)(function(){var t={},n={},r=Symbol(),e="abcdefghijklmnopqrst";return t[r]=7,e.split("").forEach(function(t){n[t]=t}),7!=i({},t)[r]||Object.keys(i({},n)).join("")!=e})?function(t,n){for(var r=y(t),e=arguments.length,i=1,o=p.f,u=d.f;i<e;)for(var c,f=g(arguments[i++]),a=o?v(f).concat(o(f)):v(f),s=a.length,l=0;l<s;)c=a[l++],h&&!u.call(f,c)||(r[c]=f[c]);return r}:i},function(t,n,r){var u=r(11),c=r(2),f=r(74);t.exports=r(10)?Object.defineProperties:function(t,n){c(t);for(var r,e=f(n),i=e.length,o=0;o<i;)u.f(t,r=e[o++],n[r]);return t}},function(t,n,r){var e=r(33),i=r(73).f,o={}.toString,u="object"==typeof window&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];t.exports.f=function(t){return u&&"[object Window]"==o.call(t)?function(t){try{return i(t)}catch(t){return u.slice()}}(t):i(e(t))}},function(t,n,r){var u=r(30),c=r(33),f=r(120)(!1),a=r(154)("IE_PROTO");t.exports=function(t,n){var r,e=c(t),i=0,o=[];for(r in e)r!=a&&u(e,r)&&o.push(r);for(;n.length>i;)u(e,r=n[i++])&&(~f(o,r)||o.push(r));return o}},function(t,n,r){var f=r(10),a=r(74),s=r(33),l=r(117).f;t.exports=function(c){return function(t){for(var n,r=s(t),e=a(r),i=e.length,o=0,u=[];o<i;)n=e[o++],f&&!l.call(r,n)||u.push(c?[n,r[n]]:r[n]);return u}}},function(t,n,r){var e=r(73),i=r(127),o=r(2),u=r(3).Reflect;t.exports=u&&u.ownKeys||function(t){var n=e.f(o(t)),r=i.f;return r?n.concat(r(t)):n}},function(t,n,r){var e=r(3).parseFloat,i=r(84).trim;t.exports=1/e(r(157)+"-0")!=-1/0?function(t){var n=i(String(t),3),r=e(n);return 0===r&&"-"==n.charAt(0)?-0:r}:e},function(t,n,r){var e=r(3).parseInt,i=r(84).trim,o=r(157),u=/^[-+]?0[xX]/;t.exports=8!==e(o+"08")||22!==e(o+"0x16")?function(t,n){var r=i(String(t),3);return e(r,n>>>0||(u.test(r)?16:10))}:e},function(t,n){t.exports=function(t){try{return{e:!1,v:t()}}catch(t){return{e:!0,v:t}}}},function(t,n,r){var e=r(2),i=r(5),o=r(151);t.exports=function(t,n){if(e(t),i(n)&&n.constructor===t)return n;var r=o.f(t);return(0,r.resolve)(n),r.promise}},function(t,n){t.exports=Object.is||function(t,n){return t===n?0!==t||1/t==1/n:t!=t&&n!=n}},function(t,n,r){var s=r(8),l=r(156),h=r(51);t.exports=function(t,n,r,e){var i=String(h(t)),o=i.length,u=void 0===r?" ":String(r),c=s(n);if(c<=o||""==u)return i;var f=c-o,a=l.call(u,Math.ceil(f/u.length));return a.length>f&&(a=a.slice(0,f)),e?a+i:i+a}},function(t,n,r){var e=r(49),i=r(8);t.exports=function(t){if(void 0===t)return 0;var n=e(t),r=i(n);if(n!==r)throw RangeError("Wrong length!");return r}},function(t,n,r){n.f=r(7)},function(t,n,r){"use strict";var e=r(170),i=r(80);t.exports=r(121)("Map",function(t){return function(){return t(this,0<arguments.length?arguments[0]:void 0)}},{get:function(t){var n=e.getEntry(i(this,"Map"),t);return n&&n.v},set:function(t,n){return e.def(i(this,"Map"),0===t?0:t,n)}},e,!0)},function(t,n,r){"use strict";var e=r(152);r(1)({target:"RegExp",proto:!0,forced:e!==/./.exec},{exec:e})},function(t,n,r){r(10)&&"g"!=/./g.flags&&r(11).f(RegExp.prototype,"flags",{configurable:!0,get:r(115)})},function(t,n,r){"use strict";var e=r(170),i=r(80);t.exports=r(121)("Set",function(t){return function(){return t(this,0<arguments.length?arguments[0]:void 0)}},{add:function(t){return e.def(i(this,"Set"),t=0===t?0:t,t)}},e)},function(t,n,r){"use strict";var o,e=r(3),i=r(50)(0),u=r(27),c=r(69),f=r(182),a=r(172),s=r(5),l=r(80),h=r(80),v=!e.ActiveXObject&&"ActiveXObject"in e,p="WeakMap",d=c.getWeak,y=Object.isExtensible,g=a.ufstore,b=function(t){return function(){return t(this,0<arguments.length?arguments[0]:void 0)}},x={get:function(t){if(s(t)){var n=d(t);return!0===n?g(l(this,p)).get(t):n?n[this._i]:void 0}},set:function(t,n){return a.def(l(this,p),t,n)}},m=t.exports=r(121)(p,b,x,a,!0,!0);h&&v&&(f((o=a.getConstructor(b,p)).prototype,x),c.NEED=!0,i(["delete","has","get","set"],function(e){var t=m.prototype,i=t[e];u(t,e,function(t,n){if(!s(t)||y(t))return i.call(this,t,n);this._f||(this._f=new o);var r=this._f[e](t,n);return"set"==e?this:r})}))},,,,function(t,n){"use strict";t.exports={init:function(){var t=document.querySelector("#page-nav");t&&!document.querySelector("#page-nav .extend.prev")&&(t.innerHTML='<a class="extend prev disabled" rel="prev">&laquo; Prev</a>'+t.innerHTML),t&&!document.querySelector("#page-nav .extend.next")&&(t.innerHTML=t.innerHTML+'<a class="extend next disabled" rel="next">Next &raquo;</a>'),yiliaConfig&&yiliaConfig.open_in_new&&document.querySelectorAll(".article-entry a:not(.article-more-a)").forEach(function(t){var n=t.getAttribute("target");n&&""!==n||t.setAttribute("target","_blank")}),yiliaConfig&&yiliaConfig.toc_hide_index&&document.querySelectorAll(".toc-number").forEach(function(t){t.style.display="none"});var n=document.querySelector("#js-aboutme");n&&0!==n.length&&(n.innerHTML=n.innerText)}}},function(t,n,r){"use strict";function e(t){return t&&t.__esModule?t:{default:t}}function i(t,n,r,e,i){var o=function(t){for(var n=t.offsetLeft,r=t.offsetParent;null!==r;)n+=r.offsetLeft,r=r.offsetParent;return n}(t),u=function(t){for(var n=t.offsetTop,r=t.offsetParent;null!==r;)n+=r.offsetTop,r=r.offsetParent;return n}(t)-n;if(u-r<=i){var c=t.$newDom;c||(c=t.cloneNode(!0),(0,a.default)(t,c),(t.$newDom=c).style.position="fixed",c.style.top=(r||u)+"px",c.style.left=o+"px",c.style.zIndex=e||2,c.style.width="100%",c.style.color="#fff"),c.style.visibility="visible",t.style.visibility="hidden"}else{t.style.visibility="visible";var f=t.$newDom;f&&(f.style.visibility="hidden")}}function o(){var t=document.querySelector(".js-overlay"),n=document.querySelector(".js-header-menu");i(t,document.body.scrollTop,-63,2,0),i(n,document.body.scrollTop,1,3,0)}var f=e(r(163)),a=e((e(r(164)),r(416))),u=e(r(134)),c=e(r(204)),s=r(135);u.default.versions.mobile&&window.screen.width<800&&(function(){for(var t=document.querySelectorAll(".js-header-menu li a"),n=window.location.pathname,r=0,e=t.length;r<e;r++){var i=t[r];o=n,u=i.getAttribute("href"),c=/\/|index.html/g,o.replace(c,"")===u.replace(c,"")&&(0,f.default)(i,"active")}var o,u,c}(),document.querySelector("#container").addEventListener("scroll",function(t){o()}),window.addEventListener("scroll",function(t){o()}),o()),(0,s.addLoadEvent)(function(){c.default.init()}),t.exports={}},,,,function(t,n,r){(function(t){"use strict";function n(t,n,r){t[n]||Object.defineProperty(t,n,{writable:!0,configurable:!0,value:r})}if(r(415),r(210),r(213),t._babelPolyfill)throw new Error("only one instance of babel-polyfill is allowed");t._babelPolyfill=!0;n(String.prototype,"padLeft","".padStart),n(String.prototype,"padRight","".padEnd),"pop,reverse,shift,keys,values,entries,indexOf,every,some,forEach,map,filter,find,findIndex,includes,join,slice,concat,push,splice,unshift,sort,lastIndexOf,reduce,reduceRight,copyWithin,fill".split(",").forEach(function(t){[][t]&&n(Array,t,Function.call.bind([][t]))})}).call(n,function(){return this}())},function(L,t){(function(t){!function(t){"use strict";function o(t,n,r,e){var o,u,c,f,i=n&&n.prototype instanceof h?n:h,a=Object.create(i.prototype),s=new p(e||[]);return a._invoke=(o=t,u=r,c=s,f=_,function(t,n){if(f===E)throw new Error("Generator is already running");if(f===M){if("throw"===t)throw n;return d()}for(c.method=t,c.arg=n;;){var r=c.delegate;if(r){var e=v(r,c);if(e){if(e===P)continue;return e}}if("next"===c.method)c.sent=c._sent=c.arg;else if("throw"===c.method){if(f===_)throw f=M,c.arg;c.dispatchException(c.arg)}else"return"===c.method&&c.abrupt("return",c.arg);f=E;var i=l(o,u,c);if("normal"===i.type){if(f=c.done?M:O,i.arg===P)continue;return{value:i.arg,done:c.done}}"throw"===i.type&&(f=M,c.method="throw",c.arg=i.arg)}}),a}function l(t,n,r){try{return{type:"normal",arg:t.call(n,r)}}catch(t){return{type:"throw",arg:t}}}function h(){}function r(){}function n(){}function e(t){["next","throw","return"].forEach(function(n){t[n]=function(t){return this._invoke(n,t)}})}function u(c){function f(t,n,r,e){var i=l(c[t],c,n);if("throw"!==i.type){var o=i.arg,u=o.value;return u&&"object"==typeof u&&y.call(u,"__await")?Promise.resolve(u.__await).then(function(t){f("next",t,r,e)},function(t){f("throw",t,r,e)}):Promise.resolve(u).then(function(t){o.value=t,r(o)},e)}e(i.arg)}var n;"object"==typeof t.process&&t.process.domain&&(f=t.process.domain.bind(f)),this._invoke=function(r,e){function t(){return new Promise(function(t,n){f(r,e,t,n)})}return n=n?n.then(t,t):t()}}function v(t,n){var r=t.iterator[n.method];if(r===a){if(n.delegate=null,"throw"===n.method){if(t.iterator.return&&(n.method="return",n.arg=a,v(t,n),"throw"===n.method))return P;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return P}var e=l(r,t.iterator,n.arg);if("throw"===e.type)return n.method="throw",n.arg=e.arg,n.delegate=null,P;var i=e.arg;return i?i.done?(n[t.resultName]=i.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=a),n.delegate=null,P):i:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,P)}function i(t){var n={tryLoc:t[0]};1 in t&&(n.catchLoc=t[1]),2 in t&&(n.finallyLoc=t[2],n.afterLoc=t[3]),this.tryEntries.push(n)}function c(t){var n=t.completion||{};n.type="normal",delete n.arg,t.completion=n}function p(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(i,this),this.reset(!0)}function f(n){if(n){var t=n[b];if(t)return t.call(n);if("function"==typeof n.next)return n;if(!isNaN(n.length)){var r=-1,e=function t(){for(;++r<n.length;)if(y.call(n,r))return t.value=n[r],t.done=!1,t;return t.value=a,t.done=!0,t};return e.next=e}}return{next:d}}function d(){return{value:a,done:!0}}var a,s=Object.prototype,y=s.hasOwnProperty,g="function"==typeof Symbol?Symbol:{},b=g.iterator||"@@iterator",x=g.asyncIterator||"@@asyncIterator",m=g.toStringTag||"@@toStringTag",S="object"==typeof L,w=t.regeneratorRuntime;if(w)S&&(L.exports=w);else{(w=t.regeneratorRuntime=S?L.exports:{}).wrap=o;var _="suspendedStart",O="suspendedYield",E="executing",M="completed",P={},j={};j[b]=function(){return this};var F=Object.getPrototypeOf,A=F&&F(F(f([])));A&&A!==s&&y.call(A,b)&&(j=A);var I=n.prototype=h.prototype=Object.create(j);r.prototype=I.constructor=n,n.constructor=r,n[m]=r.displayName="GeneratorFunction",w.isGeneratorFunction=function(t){var n="function"==typeof t&&t.constructor;return!!n&&(n===r||"GeneratorFunction"===(n.displayName||n.name))},w.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,n):(t.__proto__=n,m in t||(t[m]="GeneratorFunction")),t.prototype=Object.create(I),t},w.awrap=function(t){return{__await:t}},e(u.prototype),u.prototype[x]=function(){return this},w.AsyncIterator=u,w.async=function(t,n,r,e){var i=new u(o(t,n,r,e));return w.isGeneratorFunction(n)?i:i.next().then(function(t){return t.done?t.value:i.next()})},e(I),I[m]="Generator",I[b]=function(){return this},I.toString=function(){return"[object Generator]"},w.keys=function(r){var e=[];for(var t in r)e.push(t);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},w.values=f,p.prototype={constructor:p,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=a,this.done=!1,this.delegate=null,this.method="next",this.arg=a,this.tryEntries.forEach(c),!t)for(var n in this)"t"===n.charAt(0)&&y.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=a)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){function t(t,n){return o.type="throw",o.arg=r,e.next=t,n&&(e.method="next",e.arg=a),!!n}if(this.done)throw r;for(var e=this,n=this.tryEntries.length-1;0<=n;--n){var i=this.tryEntries[n],o=i.completion;if("root"===i.tryLoc)return t("end");if(i.tryLoc<=this.prev){var u=y.call(i,"catchLoc"),c=y.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return t(i.catchLoc,!0);if(this.prev<i.finallyLoc)return t(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return t(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return t(i.finallyLoc)}}}},abrupt:function(t,n){for(var r=this.tryEntries.length-1;0<=r;--r){var e=this.tryEntries[r];if(e.tryLoc<=this.prev&&y.call(e,"finallyLoc")&&this.prev<e.finallyLoc){var i=e;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=n&&n<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=t,o.arg=n,i?(this.method="next",this.next=i.finallyLoc,P):this.complete(o)},complete:function(t,n){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&n&&(this.next=n),P},finish:function(t){for(var n=this.tryEntries.length-1;0<=n;--n){var r=this.tryEntries[n];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),c(r),P}},catch:function(t){for(var n=this.tryEntries.length-1;0<=n;--n){var r=this.tryEntries[n];if(r.tryLoc===t){var e=r.completion;if("throw"===e.type){var i=e.arg;c(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:f(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=a),P}}}}("object"==typeof t?t:"object"==typeof window?window:"object"==typeof self?self:this)}).call(t,function(){return this}())},,,function(t,n,r){r(223),t.exports=r(46).RegExp.escape},,,,function(t,n,r){var e=r(5),i=r(123),o=r(7)("species");t.exports=function(t){var n;return i(t)&&("function"!=typeof(n=t.constructor)||n!==Array&&!i(n.prototype)||(n=void 0),e(n)&&(null===(n=n[o])&&(n=void 0))),void 0===n?Array:n}},function(t,n,r){"use strict";var e=r(4),i=Date.prototype.getTime,o=Date.prototype.toISOString,u=function(t){return 9<t?t:"0"+t};t.exports=e(function(){return"0385-07-25T07:06:39.999Z"!=o.call(new Date(-5e13-1))})||!e(function(){o.call(new Date(NaN))})?function(){if(!isFinite(i.call(this)))throw RangeError("Invalid time value");var t=this,n=t.getUTCFullYear(),r=t.getUTCMilliseconds(),e=n<0?"-":9999<n?"+":"";return e+("00000"+Math.abs(n)).slice(e?-6:-4)+"-"+u(t.getUTCMonth()+1)+"-"+u(t.getUTCDate())+"T"+u(t.getUTCHours())+":"+u(t.getUTCMinutes())+":"+u(t.getUTCSeconds())+"."+(99<r?r:"0"+u(r))+"Z"}:o},function(t,n,r){"use strict";var e=r(2),i=r(53);t.exports=function(t){if("string"!==t&&"number"!==t&&"default"!==t)throw TypeError("Incorrect hint");return i(e(this),"number"!=t)}},function(t,n,r){var c=r(74),f=r(127),a=r(117);t.exports=function(t){var n=c(t),r=f.f;if(r)for(var e,i=r(t),o=a.f,u=0;i.length>u;)o.call(t,e=i[u++])&&n.push(e);return n}},function(t,n,r){t.exports=r(118)("native-function-to-string",Function.toString)},function(t,n){t.exports=function(n,r){var e=r===Object(r)?function(t){return r[t]}:r;return function(t){return String(t).replace(n,e)}}},function(t,n,r){var e=r(1),i=r(222)(/[\\^$*+?.()|[\]{}]/g,"\\$&");e(e.S,"RegExp",{escape:function(t){return i(t)}})},function(t,n,r){var e=r(1);e(e.P,"Array",{copyWithin:r(166)}),r(67)("copyWithin")},function(t,n,r){"use strict";var e=r(1),i=r(50)(4);e(e.P+e.F*!r(48)([].every,!0),"Array",{every:function(t){return i(this,t,arguments[1])}})},function(t,n,r){var e=r(1);e(e.P,"Array",{fill:r(137)}),r(67)("fill")},function(t,n,r){"use strict";var e=r(1),i=r(50)(2);e(e.P+e.F*!r(48)([].filter,!0),"Array",{filter:function(t){return i(this,t,arguments[1])}})},function(t,n,r){"use strict";var e=r(1),i=r(50)(6),o="findIndex",u=!0;o in[]&&Array(1)[o](function(){u=!1}),e(e.P+e.F*u,"Array",{findIndex:function(t){return i(this,t,1<arguments.length?arguments[1]:void 0)}}),r(67)(o)},function(t,n,r){"use strict";var e=r(1),i=r(50)(5),o="find",u=!0;o in[]&&Array(1)[o](function(){u=!1}),e(e.P+e.F*u,"Array",{find:function(t){return i(this,t,1<arguments.length?arguments[1]:void 0)}}),r(67)(o)},function(t,n,r){"use strict";var e=r(1),i=r(50)(0),o=r(48)([].forEach,!0);e(e.P+e.F*!o,"Array",{forEach:function(t){return i(this,t,arguments[1])}})},function(t,n,r){"use strict";var h=r(47),e=r(1),v=r(17),p=r(177),d=r(145),y=r(8),g=r(139),b=r(161);e(e.S+e.F*!r(125)(function(t){Array.from(t)}),"Array",{from:function(t){var n,r,e,i,o=v(t),u="function"==typeof this?this:Array,c=arguments.length,f=1<c?arguments[1]:void 0,a=void 0!==f,s=0,l=b(o);if(a&&(f=h(f,2<c?arguments[2]:void 0,2)),null==l||u==Array&&d(l))for(r=new u(n=y(o.length));s<n;s++)g(r,s,a?f(o[s],s):o[s]);else for(i=l.call(o),r=new u;!(e=i.next()).done;s++)g(r,s,a?p(i,f,[e.value,s],!0):e.value);return r.length=s,r}})},function(t,n,r){"use strict";var e=r(1),i=r(120)(!1),o=[].indexOf,u=!!o&&1/[1].indexOf(1,-0)<0;e(e.P+e.F*(u||!r(48)(o)),"Array",{indexOf:function(t){return u?o.apply(this,arguments)||0:i(this,t,arguments[1])}})},function(t,n,r){var e=r(1);e(e.S,"Array",{isArray:r(123)})},function(t,n,r){"use strict";var e=r(1),i=r(33),o=[].join;e(e.P+e.F*(r(116)!=Object||!r(48)(o)),"Array",{join:function(t){return o.call(i(this),void 0===t?",":t)}})},function(t,n,r){"use strict";var e=r(1),i=r(33),o=r(49),u=r(8),c=[].lastIndexOf,f=!!c&&1/[1].lastIndexOf(1,-0)<0;e(e.P+e.F*(f||!r(48)(c)),"Array",{lastIndexOf:function(t){if(f)return c.apply(this,arguments)||0;var n=i(this),r=u(n.length),e=r-1;for(1<arguments.length&&(e=Math.min(e,o(arguments[1]))),e<0&&(e=r+e);0<=e;e--)if(e in n&&n[e]===t)return e||0;return-1}})},function(t,n,r){"use strict";var e=r(1),i=r(50)(1);e(e.P+e.F*!r(48)([].map,!0),"Array",{map:function(t){return i(this,t,arguments[1])}})},function(t,n,r){"use strict";var e=r(1),i=r(139);e(e.S+e.F*r(4)(function(){function t(){}return!(Array.of.call(t)instanceof t)}),"Array",{of:function(){for(var t=0,n=arguments.length,r=new("function"==typeof this?this:Array)(n);t<n;)i(r,t,arguments[t++]);return r.length=n,r}})},function(t,n,r){"use strict";var e=r(1),i=r(168);e(e.P+e.F*!r(48)([].reduceRight,!0),"Array",{reduceRight:function(t){return i(this,t,arguments.length,arguments[1],!0)}})},function(t,n,r){"use strict";var e=r(1),i=r(168);e(e.P+e.F*!r(48)([].reduce,!0),"Array",{reduce:function(t){return i(this,t,arguments.length,arguments[1],!1)}})},function(t,n,r){"use strict";var e=r(1),i=r(143),a=r(45),s=r(78),l=r(8),h=[].slice;e(e.P+e.F*r(4)(function(){i&&h.call(i)}),"Array",{slice:function(t,n){var r=l(this.length),e=a(this);if(n=void 0===n?r:n,"Array"==e)return h.call(this,t,n);for(var i=s(t,r),o=s(n,r),u=l(o-i),c=new Array(u),f=0;f<u;f++)c[f]="String"==e?this.charAt(i+f):this[i+f];return c}})},function(t,n,r){"use strict";var e=r(1),i=r(50)(3);e(e.P+e.F*!r(48)([].some,!0),"Array",{some:function(t){return i(this,t,arguments[1])}})},function(t,n,r){"use strict";var e=r(1),i=r(21),o=r(17),u=r(4),c=[].sort,f=[1,2,3];e(e.P+e.F*(u(function(){f.sort(void 0)})||!u(function(){f.sort(null)})||!r(48)(c)),"Array",{sort:function(t){return void 0===t?c.call(o(this)):c.call(o(this),i(t))}})},function(t,n,r){r(77)("Array")},function(t,n,r){var e=r(1);e(e.S,"Date",{now:function(){return(new Date).getTime()}})},function(t,n,r){var e=r(1),i=r(218);e(e.P+e.F*(Date.prototype.toISOString!==i),"Date",{toISOString:i})},function(t,n,r){"use strict";var e=r(1),i=r(17),o=r(53);e(e.P+e.F*r(4)(function(){return null!==new Date(NaN).toJSON()||1!==Date.prototype.toJSON.call({toISOString:function(){return 1}})}),"Date",{toJSON:function(t){var n=i(this),r=o(n);return"number"!=typeof r||isFinite(r)?n.toISOString():null}})},function(t,n,r){var e=r(7)("toPrimitive"),i=Date.prototype;e in i||r(26)(i,e,r(219))},function(t,n,r){var e=Date.prototype,i="Invalid Date",o="toString",u=e[o],c=e.getTime;new Date(NaN)+""!=i&&r(27)(e,o,function(){var t=c.call(this);return t==t?u.call(this):i})},function(t,n,r){var e=r(1);e(e.P,"Function",{bind:r(169)})},function(t,n,r){"use strict";var e=r(5),i=r(32),o=r(7)("hasInstance"),u=Function.prototype;o in u||r(11).f(u,o,{value:function(t){if("function"!=typeof this||!e(t))return!1;if(!e(this.prototype))return t instanceof this;for(;t=i(t);)if(this.prototype===t)return!0;return!1}})},function(t,n,r){var e=r(11).f,i=Function.prototype,o=/^\s*function ([^ (]*)/;"name"in i||r(10)&&e(i,"name",{configurable:!0,get:function(){try{return(""+this).match(o)[1]}catch(t){return""}}})},function(t,n,r){var e=r(1),i=r(180),o=Math.sqrt,u=Math.acosh;e(e.S+e.F*!(u&&710==Math.floor(u(Number.MAX_VALUE))&&u(1/0)==1/0),"Math",{acosh:function(t){return(t=+t)<1?NaN:94906265.62425156<t?Math.log(t)+Math.LN2:i(t-1+o(t-1)*o(t+1))}})},function(t,n,r){var e=r(1),i=Math.asinh;e(e.S+e.F*!(i&&0<1/i(0)),"Math",{asinh:function t(n){return isFinite(n=+n)&&0!=n?n<0?-t(-n):Math.log(n+Math.sqrt(n*n+1)):n}})},function(t,n,r){var e=r(1),i=Math.atanh;e(e.S+e.F*!(i&&1/i(-0)<0),"Math",{atanh:function(t){return 0==(t=+t)?t:Math.log((1+t)/(1-t))/2}})},function(t,n,r){var e=r(1),i=r(149);e(e.S,"Math",{cbrt:function(t){return i(t=+t)*Math.pow(Math.abs(t),1/3)}})},function(t,n,r){var e=r(1);e(e.S,"Math",{clz32:function(t){return(t>>>=0)?31-Math.floor(Math.log(t+.5)*Math.LOG2E):32}})},function(t,n,r){var e=r(1),i=Math.exp;e(e.S,"Math",{cosh:function(t){return(i(t=+t)+i(-t))/2}})},function(t,n,r){var e=r(1),i=r(148);e(e.S+e.F*(i!=Math.expm1),"Math",{expm1:i})},function(t,n,r){var e=r(1);e(e.S,"Math",{fround:r(179)})},function(t,n,r){var e=r(1),f=Math.abs;e(e.S,"Math",{hypot:function(t,n){for(var r,e,i=0,o=0,u=arguments.length,c=0;o<u;)c<(r=f(arguments[o++]))?(i=i*(e=c/r)*e+1,c=r):0<r?i+=(e=r/c)*e:i+=r;return c===1/0?1/0:c*Math.sqrt(i)}})},function(t,n,r){var e=r(1),i=Math.imul;e(e.S+e.F*r(4)(function(){return-5!=i(4294967295,5)||2!=i.length}),"Math",{imul:function(t,n){var r=65535,e=+t,i=+n,o=r&e,u=r&i;return 0|o*u+((r&e>>>16)*u+o*(r&i>>>16)<<16>>>0)}})},function(t,n,r){var e=r(1);e(e.S,"Math",{log10:function(t){return Math.log(t)*Math.LOG10E}})},function(t,n,r){var e=r(1);e(e.S,"Math",{log1p:r(180)})},function(t,n,r){var e=r(1);e(e.S,"Math",{log2:function(t){return Math.log(t)/Math.LN2}})},function(t,n,r){var e=r(1);e(e.S,"Math",{sign:r(149)})},function(t,n,r){var e=r(1),i=r(148),o=Math.exp;e(e.S+e.F*r(4)(function(){return-2e-17!=!Math.sinh(-2e-17)}),"Math",{sinh:function(t){return Math.abs(t=+t)<1?(i(t)-i(-t))/2:(o(t-1)-o(-t-1))*(Math.E/2)}})},function(t,n,r){var e=r(1),i=r(148),o=Math.exp;e(e.S,"Math",{tanh:function(t){var n=i(t=+t),r=i(-t);return n==1/0?1:r==1/0?-1:(n-r)/(o(t)+o(-t))}})},function(t,n,r){var e=r(1);e(e.S,"Math",{trunc:function(t){return(0<t?Math.floor:Math.ceil)(t)}})},function(t,n,r){"use strict";var e=r(3),i=r(30),o=r(45),u=r(144),s=r(53),c=r(4),f=r(73).f,a=r(31).f,l=r(11).f,h=r(84).trim,v="Number",p=e[v],d=p,y=p.prototype,g=o(r(72)(y))==v,b="trim"in String.prototype,x=function(t){var n=s(t,!1);if("string"==typeof n&&2<n.length){var r,e,i,o=(n=b?n.trim():h(n,3)).charCodeAt(0);if(43===o||45===o){if(88===(r=n.charCodeAt(2))||120===r)return NaN}else if(48===o){switch(n.charCodeAt(1)){case 66:case 98:e=2,i=49;break;case 79:case 111:e=8,i=55;break;default:return+n}for(var u,c=n.slice(2),f=0,a=c.length;f<a;f++)if((u=c.charCodeAt(f))<48||i<u)return NaN;return parseInt(c,e)}}return+n};if(!p(" 0o1")||!p("0b1")||p("+0x1")){p=function(t){var n=arguments.length<1?0:t,r=this;return r instanceof p&&(g?c(function(){y.valueOf.call(r)}):o(r)!=v)?u(new d(x(n)),r,p):x(n)};for(var m,S=r(10)?f(d):"MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITY,POSITIVE_INFINITY,EPSILON,isFinite,isInteger,isNaN,isSafeInteger,MAX_SAFE_INTEGER,MIN_SAFE_INTEGER,parseFloat,parseInt,isInteger".split(","),w=0;S.length>w;w++)i(d,m=S[w])&&!i(p,m)&&l(p,m,a(d,m));(p.prototype=y).constructor=p,r(27)(e,v,p)}},function(t,n,r){var e=r(1);e(e.S,"Number",{EPSILON:Math.pow(2,-52)})},function(t,n,r){var e=r(1),i=r(3).isFinite;e(e.S,"Number",{isFinite:function(t){return"number"==typeof t&&i(t)}})},function(t,n,r){var e=r(1);e(e.S,"Number",{isInteger:r(176)})},function(t,n,r){var e=r(1);e(e.S,"Number",{isNaN:function(t){return t!=t}})},function(t,n,r){var e=r(1),i=r(176),o=Math.abs;e(e.S,"Number",{isSafeInteger:function(t){return i(t)&&o(t)<=9007199254740991}})},function(t,n,r){var e=r(1);e(e.S,"Number",{MAX_SAFE_INTEGER:9007199254740991})},function(t,n,r){var e=r(1);e(e.S,"Number",{MIN_SAFE_INTEGER:-9007199254740991})},function(t,n,r){var e=r(1),i=r(188);e(e.S+e.F*(Number.parseFloat!=i),"Number",{parseFloat:i})},function(t,n,r){var e=r(1),i=r(189);e(e.S+e.F*(Number.parseInt!=i),"Number",{parseInt:i})},function(t,n,r){"use strict";var e=r(1),a=r(49),s=r(165),l=r(156),i=1..toFixed,o=Math.floor,u=[0,0,0,0,0,0],h="Number.toFixed: incorrect invocation!",v=function(t,n){for(var r=-1,e=n;++r<6;)e+=t*u[r],u[r]=e%1e7,e=o(e/1e7)},p=function(t){for(var n=6,r=0;0<=--n;)r+=u[n],u[n]=o(r/t),r=r%t*1e7},d=function(){for(var t=6,n="";0<=--t;)if(""!==n||0===t||0!==u[t]){var r=String(u[t]);n=""===n?r:n+l.call("0",7-r.length)+r}return n},y=function(t,n,r){return 0===n?r:n%2==1?y(t,n-1,r*t):y(t*t,n/2,r)};e(e.P+e.F*(!!i&&("0.000"!==8e-5.toFixed(3)||"1"!==.9.toFixed(0)||"1.25"!==1.255.toFixed(2)||"1000000000000000128"!==(0xde0b6b3a7640080).toFixed(0))||!r(4)(function(){i.call({})})),"Number",{toFixed:function(t){var n,r,e,i,o=s(this,h),u=a(t),c="",f="0";if(u<0||20<u)throw RangeError(h);if(o!=o)return"NaN";if(o<=-1e21||1e21<=o)return String(o);if(o<0&&(c="-",o=-o),1e-21<o)if(r=(n=function(t){for(var n=0,r=t;4096<=r;)n+=12,r/=4096;for(;2<=r;)n+=1,r/=2;return n}(o*y(2,69,1))-69)<0?o*y(2,-n,1):o/y(2,n,1),r*=4503599627370496,0<(n=52-n)){for(v(0,r),e=u;7<=e;)v(1e7,0),e-=7;for(v(y(10,e,1),0),e=n-1;23<=e;)p(1<<23),e-=23;p(1<<e),v(1,1),p(2),f=d()}else v(0,r),v(1<<-n,0),f=d()+l.call("0",u);return f=0<u?c+((i=f.length)<=u?"0."+l.call("0",u-i)+f:f.slice(0,i-u)+"."+f.slice(i-u)):c+f}})},function(t,n,r){"use strict";var e=r(1),i=r(4),o=r(165),u=1..toPrecision;e(e.P+e.F*(i(function(){return"1"!==u.call(1,void 0)})||!i(function(){u.call({})})),"Number",{toPrecision:function(t){var n=o(this,"Number#toPrecision: incorrect invocation!");return void 0===t?u.call(n):u.call(n,t)}})},function(t,n,r){var e=r(1);e(e.S+e.F,"Object",{assign:r(182)})},function(t,n,r){var e=r(1);e(e.S,"Object",{create:r(72)})},function(t,n,r){var e=r(1);e(e.S+e.F*!r(10),"Object",{defineProperties:r(183)})},function(t,n,r){var e=r(1);e(e.S+e.F*!r(10),"Object",{defineProperty:r(11).f})},function(t,n,r){var e=r(5),i=r(69).onFreeze;r(52)("freeze",function(n){return function(t){return n&&e(t)?n(i(t)):t}})},function(t,n,r){var e=r(33),i=r(31).f;r(52)("getOwnPropertyDescriptor",function(){return function(t,n){return i(e(t),n)}})},function(t,n,r){r(52)("getOwnPropertyNames",function(){return r(184).f})},function(t,n,r){var e=r(17),i=r(32);r(52)("getPrototypeOf",function(){return function(t){return i(e(t))}})},function(t,n,r){var e=r(5);r(52)("isExtensible",function(n){return function(t){return!!e(t)&&(!n||n(t))}})},function(t,n,r){var e=r(5);r(52)("isFrozen",function(n){return function(t){return!e(t)||!!n&&n(t)}})},function(t,n,r){var e=r(5);r(52)("isSealed",function(n){return function(t){return!e(t)||!!n&&n(t)}})},function(t,n,r){var e=r(1);e(e.S,"Object",{is:r(192)})},function(t,n,r){var e=r(17),i=r(74);r(52)("keys",function(){return function(t){return i(e(t))}})},function(t,n,r){var e=r(5),i=r(69).onFreeze;r(52)("preventExtensions",function(n){return function(t){return n&&e(t)?n(i(t)):t}})},function(t,n,r){var e=r(5),i=r(69).onFreeze;r(52)("seal",function(n){return function(t){return n&&e(t)?n(i(t)):t}})},function(t,n,r){var e=r(1);e(e.S,"Object",{setPrototypeOf:r(153).set})},function(t,n,r){"use strict";var e=r(81),i={};i[r(7)("toStringTag")]="z",i+""!="[object z]"&&r(27)(Object.prototype,"toString",function(){return"[object "+e(this)+"]"},!0)},function(t,n,r){var e=r(1),i=r(188);e(e.G+e.F*(parseFloat!=i),{parseFloat:i})},function(t,n,r){var e=r(1),i=r(189);e(e.G+e.F*(parseInt!=i),{parseInt:i})},function(t,n,r){"use strict";var e,i,o,u,c=r(68),f=r(3),a=r(47),s=r(81),l=r(1),h=r(5),v=r(21),p=r(70),d=r(71),y=r(119),g=r(158).set,b=r(150)(),x=r(151),m=r(190),S=r(133),w=r(191),_="Promise",O=f.TypeError,E=f.process,M=E&&E.versions,P=M&&M.v8||"",j=f[_],F="process"==s(E),A=function(){},I=i=x.f,L=!!function(){try{var t=j.resolve(1),n=(t.constructor={})[r(7)("species")]=function(t){t(A,A)};return(F||"function"==typeof PromiseRejectionEvent)&&t.then(A)instanceof n&&0!==P.indexOf("6.6")&&-1===S.indexOf("Chrome/66")}catch(t){}}(),N=function(t){var n;return!(!h(t)||"function"!=typeof(n=t.then))&&n},T=function(s,r){if(!s._n){s._n=!0;var e=s._c;b(function(){for(var f=s._v,a=1==s._s,t=0,n=function(t){var n,r,e,i=a?t.ok:t.fail,o=t.resolve,u=t.reject,c=t.domain;try{i?(a||(2==s._h&&C(s),s._h=1),!0===i?n=f:(c&&c.enter(),n=i(f),c&&(c.exit(),e=!0)),n===t.promise?u(O("Promise-chain cycle")):(r=N(n))?r.call(n,o,u):o(n)):u(f)}catch(t){c&&!e&&c.exit(),u(t)}};e.length>t;)n(e[t++]);s._c=[],s._n=!1,r&&!s._h&&k(s)})}},k=function(o){g.call(f,function(){var t,n,r,e=o._v,i=R(o);if(i&&(t=m(function(){F?E.emit("unhandledRejection",e,o):(n=f.onunhandledrejection)?n({promise:o,reason:e}):(r=f.console)&&r.error&&r.error("Unhandled promise rejection",e)}),o._h=F||R(o)?2:1),o._a=void 0,i&&t.e)throw t.v})},R=function(t){return 1!==t._h&&0===(t._a||t._c).length},C=function(n){g.call(f,function(){var t;F?E.emit("rejectionHandled",n):(t=f.onrejectionhandled)&&t({promise:n,reason:n._v})})},D=function(t){var n=this;n._d||(n._d=!0,(n=n._w||n)._v=t,n._s=2,n._a||(n._a=n._c.slice()),T(n,!0))},G=function(t){var r,e=this;if(!e._d){e._d=!0,e=e._w||e;try{if(e===t)throw O("Promise can't be resolved itself");(r=N(t))?b(function(){var n={_w:e,_d:!1};try{r.call(t,a(G,n,1),a(D,n,1))}catch(t){D.call(n,t)}}):(e._v=t,e._s=1,T(e,!1))}catch(t){D.call({_w:e,_d:!1},t)}}};L||(j=function(t){p(this,j,_,"_h"),v(t),e.call(this);try{t(a(G,this,1),a(D,this,1))}catch(t){D.call(this,t)}},(e=function(t){this._c=[],this._a=void 0,this._s=0,this._d=!1,this._v=void 0,this._h=0,this._n=!1}).prototype=r(76)(j.prototype,{then:function(t,n){var r=I(y(this,j));return r.ok="function"!=typeof t||t,r.fail="function"==typeof n&&n,r.domain=F?E.domain:void 0,this._c.push(r),this._a&&this._a.push(r),this._s&&T(this,!1),r.promise},catch:function(t){return this.then(void 0,t)}}),o=function(){var t=new e;this.promise=t,this.resolve=a(G,t,1),this.reject=a(D,t,1)},x.f=I=function(t){return t===j||t===u?new o(t):i(t)}),l(l.G+l.W+l.F*!L,{Promise:j}),r(83)(j,_),r(77)(_),u=r(46)[_],l(l.S+l.F*!L,_,{reject:function(t){var n=I(this);return(0,n.reject)(t),n.promise}}),l(l.S+l.F*(c||!L),_,{resolve:function(t){return w(c&&this===u?j:this,t)}}),l(l.S+l.F*!(L&&r(125)(function(t){j.all(t).catch(A)})),_,{all:function(t){var u=this,n=I(u),c=n.resolve,f=n.reject,r=m(function(){var e=[],i=0,o=1;d(t,!1,function(t){var n=i++,r=!1;e.push(void 0),o++,u.resolve(t).then(function(t){r||(r=!0,e[n]=t,--o||c(e))},f)}),--o||c(e)});return r.e&&f(r.v),n.promise},race:function(t){var n=this,r=I(n),e=r.reject,i=m(function(){d(t,!1,function(t){n.resolve(t).then(r.resolve,e)})});return i.e&&e(i.v),r.promise}})},function(t,n,r){var e=r(1),o=r(21),u=r(2),c=(r(3).Reflect||{}).apply,f=Function.apply;e(e.S+e.F*!r(4)(function(){c(function(){})}),"Reflect",{apply:function(t,n,r){var e=o(t),i=u(r);return c?c(e,n,i):f.call(e,n,i)}})},function(t,n,r){var e=r(1),c=r(72),f=r(21),a=r(2),s=r(5),i=r(4),l=r(169),h=(r(3).Reflect||{}).construct,v=i(function(){function t(){}return!(h(function(){},[],t)instanceof t)}),p=!i(function(){h(function(){})});e(e.S+e.F*(v||p),"Reflect",{construct:function(t,n){f(t),a(n);var r=arguments.length<3?t:f(arguments[2]);if(p&&!v)return h(t,n,r);if(t==r){switch(n.length){case 0:return new t;case 1:return new t(n[0]);case 2:return new t(n[0],n[1]);case 3:return new t(n[0],n[1],n[2]);case 4:return new t(n[0],n[1],n[2],n[3])}var e=[null];return e.push.apply(e,n),new(l.apply(t,e))}var i=r.prototype,o=c(s(i)?i:Object.prototype),u=Function.apply.call(t,o,n);return s(u)?u:o}})},function(t,n,r){var e=r(11),i=r(1),o=r(2),u=r(53);i(i.S+i.F*r(4)(function(){Reflect.defineProperty(e.f({},1,{value:1}),1,{value:2})}),"Reflect",{defineProperty:function(t,n,r){o(t),n=u(n,!0),o(r);try{return e.f(t,n,r),!0}catch(t){return!1}}})},function(t,n,r){var e=r(1),i=r(31).f,o=r(2);e(e.S,"Reflect",{deleteProperty:function(t,n){var r=i(o(t),n);return!(r&&!r.configurable)&&delete t[n]}})},function(t,n,r){"use strict";var e=r(1),i=r(2),o=function(t){this._t=i(t),this._i=0;var n,r=this._k=[];for(n in t)r.push(n)};r(146)(o,"Object",function(){var t,n=this._k;do{if(this._i>=n.length)return{value:void 0,done:!0}}while(!((t=n[this._i++])in this._t));return{value:t,done:!1}}),e(e.S,"Reflect",{enumerate:function(t){return new o(t)}})},function(t,n,r){var e=r(31),i=r(1),o=r(2);i(i.S,"Reflect",{getOwnPropertyDescriptor:function(t,n){return e.f(o(t),n)}})},function(t,n,r){var e=r(1),i=r(32),o=r(2);e(e.S,"Reflect",{getPrototypeOf:function(t){return i(o(t))}})},function(t,n,r){var u=r(31),c=r(32),f=r(30),e=r(1),a=r(5),s=r(2);e(e.S,"Reflect",{get:function t(n,r){var e,i,o=arguments.length<3?n:arguments[2];return s(n)===o?n[r]:(e=u.f(n,r))?f(e,"value")?e.value:void 0!==e.get?e.get.call(o):void 0:a(i=c(n))?t(i,r,o):void 0}})},function(t,n,r){var e=r(1);e(e.S,"Reflect",{has:function(t,n){return n in t}})},function(t,n,r){var e=r(1),i=r(2),o=Object.isExtensible;e(e.S,"Reflect",{isExtensible:function(t){return i(t),!o||o(t)}})},function(t,n,r){var e=r(1);e(e.S,"Reflect",{ownKeys:r(187)})},function(t,n,r){var e=r(1),i=r(2),o=Object.preventExtensions;e(e.S,"Reflect",{preventExtensions:function(t){i(t);try{return o&&o(t),!0}catch(t){return!1}}})},function(t,n,r){var e=r(1),i=r(153);i&&e(e.S,"Reflect",{setPrototypeOf:function(t,n){i.check(t,n);try{return i.set(t,n),!0}catch(t){return!1}}})},function(t,n,r){var f=r(11),a=r(31),s=r(32),l=r(30),e=r(1),h=r(75),v=r(2),p=r(5);e(e.S,"Reflect",{set:function t(n,r,e){var i,o,u=arguments.length<4?n:arguments[3],c=a.f(v(n),r);if(!c){if(p(o=s(n)))return t(o,r,e,u);c=h(0)}if(l(c,"value")){if(!1===c.writable||!p(u))return!1;if(i=a.f(u,r)){if(i.get||i.set||!1===i.writable)return!1;i.value=e,f.f(u,r,i)}else f.f(u,r,h(0,e));return!0}return void 0!==c.set&&(c.set.call(u,e),!0)}})},function(t,n,r){var e=r(3),o=r(144),i=r(11).f,u=r(73).f,c=r(124),f=r(115),a=e.RegExp,s=a,l=a.prototype,h=/a/g,v=/a/g,p=new a(h)!==h;if(r(10)&&(!p||r(4)(function(){return v[r(7)("match")]=!1,a(h)!=h||a(v)==v||"/a/i"!=a(h,"i")}))){a=function(t,n){var r=this instanceof a,e=c(t),i=void 0===n;return!r&&e&&t.constructor===a&&i?t:o(p?new s(e&&!i?t.source:t,n):s((e=t instanceof a)?t.source:t,e&&i?f.call(t):n),r?this:l,a)};for(var d=function(n){n in a||i(a,n,{configurable:!0,get:function(){return s[n]},set:function(t){s[n]=t}})},y=u(s),g=0;y.length>g;)d(y[g++]);(l.constructor=a).prototype=l,r(27)(e,"RegExp",a)}r(77)("RegExp")},function(t,n,r){"use strict";var l=r(2),h=r(8),v=r(136),p=r(128);r(122)("match",1,function(e,i,a,s){return[function(t){var n=e(this),r=null==t?void 0:t[i];return void 0!==r?r.call(t,n):new RegExp(t)[i](String(n))},function(t){var n=s(a,t,this);if(n.done)return n.value;var r=l(t),e=String(this);if(!r.global)return p(r,e);for(var i,o=r.unicode,u=[],c=r.lastIndex=0;null!==(i=p(r,e));){var f=String(i[0]);""===(u[c]=f)&&(r.lastIndex=v(e,h(r.lastIndex),o)),c++}return 0===c?null:u}]})},function(t,n,r){"use strict";var O=r(2),e=r(17),E=r(8),M=r(49),P=r(136),j=r(128),F=Math.max,A=Math.min,h=Math.floor,v=/\$([$&`']|\d\d?|<[^>]*>)/g,p=/\$([$&`']|\d\d?)/g;r(122)("replace",2,function(i,o,S,w){function _(o,u,c,f,a,t){var s=c+o.length,l=f.length,n=p;return void 0!==a&&(a=e(a),n=v),S.call(t,n,function(t,n){var r;switch(n.charAt(0)){case"$":return"$";case"&":return o;case"`":return u.slice(0,c);case"'":return u.slice(s);case"<":r=a[n.slice(1,-1)];break;default:var e=+n;if(0===e)return t;if(l<e){var i=h(e/10);return 0===i?t:i<=l?void 0===f[i-1]?n.charAt(1):f[i-1]+n.charAt(1):t}r=f[e-1]}return void 0===r?"":r})}return[function(t,n){var r=i(this),e=null==t?void 0:t[o];return void 0!==e?e.call(t,r,n):S.call(String(r),t,n)},function(t,n){var r=w(S,t,this,n);if(r.done)return r.value;var e=O(t),i=String(this),o="function"==typeof n;o||(n=String(n));var u,c=e.global;if(c){var f=e.unicode;e.lastIndex=0}for(var a=[];;){var s=j(e,i);if(null===s)break;if(a.push(s),!c)break;""===String(s[0])&&(e.lastIndex=P(i,E(e.lastIndex),f))}for(var l="",h=0,v=0;v<a.length;v++){s=a[v];for(var p=String(s[0]),d=F(A(M(s.index),i.length),0),y=[],g=1;g<s.length;g++)y.push(void 0===(u=s[g])?u:String(u));var b=s.groups;if(o){var x=[p].concat(y,d,i);void 0!==b&&x.push(b);var m=String(n.apply(void 0,x))}else m=_(p,i,d,y,b,n);h<=d&&(l+=i.slice(h,d)+m,h=d+p.length)}return l+i.slice(h)}]})},function(t,n,r){"use strict";var f=r(2),a=r(192),s=r(128);r(122)("search",1,function(e,i,u,c){return[function(t){var n=e(this),r=null==t?void 0:t[i];return void 0!==r?r.call(t,n):new RegExp(t)[i](String(n))},function(t){var n=c(u,t,this);if(n.done)return n.value;var r=f(t),e=String(this),i=r.lastIndex;a(i,0)||(r.lastIndex=0);var o=s(r,e);return a(r.lastIndex,i)||(r.lastIndex=i),null===o?-1:o.index}]})},function(t,n,r){"use strict";var l=r(124),x=r(2),m=r(119),S=r(136),w=r(8),_=r(128),h=r(152),e=r(4),O=Math.min,v=[].push,u="split",p="length",d="lastIndex",E=4294967295,M=!e(function(){RegExp(E,"y")});r(122)("split",2,function(i,o,y,g){var b;return b="c"=="abbc"[u](/(b)*/)[1]||4!="test"[u](/(?:)/,-1)[p]||2!="ab"[u](/(?:ab)*/)[p]||4!="."[u](/(.?)(.?)/)[p]||1<"."[u](/()()/)[p]||""[u](/.?/)[p]?function(t,n){var r=String(this);if(void 0===t&&0===n)return[];if(!l(t))return y.call(r,t,n);for(var e,i,o,u=[],c=(t.ignoreCase?"i":"")+(t.multiline?"m":"")+(t.unicode?"u":"")+(t.sticky?"y":""),f=0,a=void 0===n?E:n>>>0,s=new RegExp(t.source,c+"g");(e=h.call(s,r))&&!(f<(i=s[d])&&(u.push(r.slice(f,e.index)),1<e[p]&&e.index<r[p]&&v.apply(u,e.slice(1)),o=e[0][p],f=i,u[p]>=a));)s[d]===e.index&&s[d]++;return f===r[p]?!o&&s.test("")||u.push(""):u.push(r.slice(f)),u[p]>a?u.slice(0,a):u}:"0"[u](void 0,0)[p]?function(t,n){return void 0===t&&0===n?[]:y.call(this,t,n)}:y,[function(t,n){var r=i(this),e=null==t?void 0:t[o];return void 0!==e?e.call(t,r,n):b.call(String(r),t,n)},function(t,n){var r=g(b,t,this,n,b!==y);if(r.done)return r.value;var e=x(t),i=String(this),o=m(e,RegExp),u=e.unicode,c=(e.ignoreCase?"i":"")+(e.multiline?"m":"")+(e.unicode?"u":"")+(M?"y":"g"),f=new o(M?e:"^(?:"+e.source+")",c),a=void 0===n?E:n>>>0;if(0===a)return[];if(0===i.length)return null===_(f,i)?[i]:[];for(var s=0,l=0,h=[];l<i.length;){f.lastIndex=M?l:0;var v,p=_(f,M?i:i.slice(l));if(null===p||(v=O(w(f.lastIndex+(M?0:l)),i.length))===s)l=S(i,l,u);else{if(h.push(i.slice(s,l)),h.length===a)return h;for(var d=1;d<=p.length-1;d++)if(h.push(p[d]),h.length===a)return h;l=s=v}}return h.push(i.slice(s)),h}]})},function(t,n,r){"use strict";r(198);var e=r(2),i=r(115),o=r(10),u="toString",c=/./[u],f=function(t){r(27)(RegExp.prototype,u,t,!0)};r(4)(function(){return"/a/b"!=c.call({source:"a",flags:"b"})})?f(function(){var t=e(this);return"/".concat(t.source,"/","flags"in t?t.flags:!o&&t instanceof RegExp?i.call(t):void 0)}):c.name!=u&&f(function(){return c.call(this)})},function(t,n,r){"use strict";r(28)("anchor",function(n){return function(t){return n(this,"a","name",t)}})},function(t,n,r){"use strict";r(28)("big",function(t){return function(){return t(this,"big","","")}})},function(t,n,r){"use strict";r(28)("blink",function(t){return function(){return t(this,"blink","","")}})},function(t,n,r){"use strict";r(28)("bold",function(t){return function(){return t(this,"b","","")}})},function(t,n,r){"use strict";var e=r(1),i=r(131)(!1);e(e.P,"String",{codePointAt:function(t){return i(this,t)}})},function(t,n,r){"use strict";var e=r(1),u=r(8),c=r(155),f="endsWith",a=""[f];e(e.P+e.F*r(142)(f),"String",{endsWith:function(t){var n=c(this,t,f),r=1<arguments.length?arguments[1]:void 0,e=u(n.length),i=void 0===r?e:Math.min(u(r),e),o=String(t);return a?a.call(n,o,i):n.slice(i-o.length,i)===o}})},function(t,n,r){"use strict";r(28)("fixed",function(t){return function(){return t(this,"tt","","")}})},function(t,n,r){"use strict";r(28)("fontcolor",function(n){return function(t){return n(this,"font","color",t)}})},function(t,n,r){"use strict";r(28)("fontsize",function(n){return function(t){return n(this,"font","size",t)}})},function(t,n,r){var e=r(1),o=r(78),u=String.fromCharCode,i=String.fromCodePoint;e(e.S+e.F*(!!i&&1!=i.length),"String",{fromCodePoint:function(t){for(var n,r=[],e=arguments.length,i=0;i<e;){if(n=+arguments[i++],o(n,1114111)!==n)throw RangeError(n+" is not a valid code point");r.push(n<65536?u(n):u(55296+((n-=65536)>>10),n%1024+56320))}return r.join("")}})},function(t,n,r){"use strict";var e=r(1),i=r(155);e(e.P+e.F*r(142)("includes"),"String",{includes:function(t){return!!~i(this,t,"includes").indexOf(t,1<arguments.length?arguments[1]:void 0)}})},function(t,n,r){"use strict";r(28)("italics",function(t){return function(){return t(this,"i","","")}})},function(t,n,r){"use strict";var e=r(131)(!0);r(147)(String,"String",function(t){this._t=String(t),this._i=0},function(){var t,n=this._t,r=this._i;return r>=n.length?{value:void 0,done:!0}:(t=e(n,r),this._i+=t.length,{value:t,done:!1})})},function(t,n,r){"use strict";r(28)("link",function(n){return function(t){return n(this,"a","href",t)}})},function(t,n,r){var e=r(1),u=r(33),c=r(8);e(e.S,"String",{raw:function(t){for(var n=u(t.raw),r=c(n.length),e=arguments.length,i=[],o=0;o<r;)i.push(String(n[o++])),o<e&&i.push(String(arguments[o]));return i.join("")}})},function(t,n,r){var e=r(1);e(e.P,"String",{repeat:r(156)})},function(t,n,r){"use strict";r(28)("small",function(t){return function(){return t(this,"small","","")}})},function(t,n,r){"use strict";var e=r(1),i=r(8),o=r(155),u="startsWith",c=""[u];e(e.P+e.F*r(142)(u),"String",{startsWith:function(t){var n=o(this,t,u),r=i(Math.min(1<arguments.length?arguments[1]:void 0,n.length)),e=String(t);return c?c.call(n,e,r):n.slice(r,r+e.length)===e}})},function(t,n,r){"use strict";r(28)("strike",function(t){return function(){return t(this,"strike","","")}})},function(t,n,r){"use strict";r(28)("sub",function(t){return function(){return t(this,"sub","","")}})},function(t,n,r){"use strict";r(28)("sup",function(t){return function(){return t(this,"sup","","")}})},function(t,n,r){"use strict";r(84)("trim",function(t){return function(){return t(this,3)}})},function(t,n,r){"use strict";var e=r(3),u=r(30),i=r(10),o=r(1),c=r(27),f=r(69).KEY,a=r(4),s=r(118),l=r(83),h=r(79),v=r(7),p=r(195),d=r(160),y=r(220),g=r(123),b=r(2),x=r(5),m=r(17),S=r(33),w=r(53),_=r(75),O=r(72),E=r(184),M=r(31),P=r(127),j=r(11),F=r(74),A=M.f,I=j.f,L=E.f,N=e.Symbol,T=e.JSON,k=T&&T.stringify,R="prototype",C=v("_hidden"),D=v("toPrimitive"),G={}.propertyIsEnumerable,W=s("symbol-registry"),U=s("symbols"),V=s("op-symbols"),B=Object[R],q="function"==typeof N&&!!P.f,z=e.QObject,H=!z||!z[R]||!z[R].findChild,K=i&&a(function(){return 7!=O(I({},"a",{get:function(){return I(this,"a",{value:7}).a}})).a})?function(t,n,r){var e=A(B,n);e&&delete B[n],I(t,n,r),e&&t!==B&&I(B,n,e)}:I,J=function(t){var n=U[t]=O(N[R]);return n._k=t,n},$=q&&"symbol"==typeof N.iterator?function(t){return"symbol"==typeof t}:function(t){return t instanceof N},Y=function(t,n,r){return t===B&&Y(V,n,r),b(t),n=w(n,!0),b(r),u(U,n)?(r.enumerable?(u(t,C)&&t[C][n]&&(t[C][n]=!1),r=O(r,{enumerable:_(0,!1)})):(u(t,C)||I(t,C,_(1,{})),t[C][n]=!0),K(t,n,r)):I(t,n,r)},X=function(t,n){b(t);for(var r,e=y(n=S(n)),i=0,o=e.length;i<o;)Y(t,r=e[i++],n[r]);return t},Q=function(t){var n=G.call(this,t=w(t,!0));return!(this===B&&u(U,t)&&!u(V,t))&&(!(n||!u(this,t)||!u(U,t)||u(this,C)&&this[C][t])||n)},Z=function(t,n){if(t=S(t),n=w(n,!0),t!==B||!u(U,n)||u(V,n)){var r=A(t,n);return!r||!u(U,n)||u(t,C)&&t[C][n]||(r.enumerable=!0),r}},tt=function(t){for(var n,r=L(S(t)),e=[],i=0;r.length>i;)u(U,n=r[i++])||n==C||n==f||e.push(n);return e},nt=function(t){for(var n,r=t===B,e=L(r?V:S(t)),i=[],o=0;e.length>o;)!u(U,n=e[o++])||r&&!u(B,n)||i.push(U[n]);return i};q||(c((N=function(){if(this instanceof N)throw TypeError("Symbol is not a constructor!");var n=h(0<arguments.length?arguments[0]:void 0),r=function(t){this===B&&r.call(V,t),u(this,C)&&u(this[C],n)&&(this[C][n]=!1),K(this,n,_(1,t))};return i&&H&&K(B,n,{configurable:!0,set:r}),J(n)})[R],"toString",function(){return this._k}),M.f=Z,j.f=Y,r(73).f=E.f=tt,r(117).f=Q,P.f=nt,i&&!r(68)&&c(B,"propertyIsEnumerable",Q,!0),p.f=function(t){return J(v(t))}),o(o.G+o.W+o.F*!q,{Symbol:N});for(var rt="hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables".split(","),et=0;rt.length>et;)v(rt[et++]);for(var it=F(v.store),ot=0;it.length>ot;)d(it[ot++]);o(o.S+o.F*!q,"Symbol",{for:function(t){return u(W,t+="")?W[t]:W[t]=N(t)},keyFor:function(t){if(!$(t))throw TypeError(t+" is not a symbol!");for(var n in W)if(W[n]===t)return n},useSetter:function(){H=!0},useSimple:function(){H=!1}}),o(o.S+o.F*!q,"Object",{create:function(t,n){return void 0===n?O(t):X(O(t),n)},defineProperty:Y,defineProperties:X,getOwnPropertyDescriptor:Z,getOwnPropertyNames:tt,getOwnPropertySymbols:nt});var ut=a(function(){P.f(1)});o(o.S+o.F*ut,"Object",{getOwnPropertySymbols:function(t){return P.f(m(t))}}),T&&o(o.S+o.F*(!q||a(function(){var t=N();return"[null]"!=k([t])||"{}"!=k({a:t})||"{}"!=k(Object(t))})),"JSON",{stringify:function(t){for(var n,r,e=[t],i=1;arguments.length>i;)e.push(arguments[i++]);if(r=n=e[1],(x(n)||void 0!==t)&&!$(t))return g(n)||(n=function(t,n){if("function"==typeof r&&(n=r.call(this,t,n)),!$(n))return n}),e[1]=n,k.apply(T,e)}}),N[R][D]||r(26)(N[R],D,N[R].valueOf),l(N,"Symbol"),l(Math,"Math",!0),l(e.JSON,"JSON",!0)},function(t,n,r){"use strict";var e=r(1),i=r(132),o=r(159),a=r(2),s=r(78),l=r(8),u=r(5),c=r(3).ArrayBuffer,h=r(119),v=o.ArrayBuffer,p=o.DataView,f=i.ABV&&c.isView,d=v.prototype.slice,y=i.VIEW,g="ArrayBuffer";e(e.G+e.W+e.F*(c!==v),{ArrayBuffer:v}),e(e.S+e.F*!i.CONSTR,g,{isView:function(t){return f&&f(t)||u(t)&&y in t}}),e(e.P+e.U+e.F*r(4)(function(){return!new v(2).slice(1,void 0).byteLength}),g,{slice:function(t,n){if(void 0!==d&&void 0===n)return d.call(a(this),t);for(var r=a(this).byteLength,e=s(t,r),i=s(void 0===n?r:n,r),o=new(h(this,v))(l(i-e)),u=new p(this),c=new p(o),f=0;e<i;)c.setUint8(f++,u.getUint8(e++));return o}}),r(77)(g)},function(t,n,r){var e=r(1);e(e.G+e.W+e.F*!r(132).ABV,{DataView:r(159).DataView})},function(t,n,r){r(57)("Float32",4,function(e){return function(t,n,r){return e(this,t,n,r)}})},function(t,n,r){r(57)("Float64",8,function(e){return function(t,n,r){return e(this,t,n,r)}})},function(t,n,r){r(57)("Int16",2,function(e){return function(t,n,r){return e(this,t,n,r)}})},function(t,n,r){r(57)("Int32",4,function(e){return function(t,n,r){return e(this,t,n,r)}})},function(t,n,r){r(57)("Int8",1,function(e){return function(t,n,r){return e(this,t,n,r)}})},function(t,n,r){r(57)("Uint16",2,function(e){return function(t,n,r){return e(this,t,n,r)}})},function(t,n,r){r(57)("Uint32",4,function(e){return function(t,n,r){return e(this,t,n,r)}})},function(t,n,r){r(57)("Uint8",1,function(e){return function(t,n,r){return e(this,t,n,r)}})},function(t,n,r){r(57)("Uint8",1,function(e){return function(t,n,r){return e(this,t,n,r)}},!0)},function(t,n,r){"use strict";var e=r(172),i=r(80);r(121)("WeakSet",function(t){return function(){return t(this,0<arguments.length?arguments[0]:void 0)}},{add:function(t){return e.def(i(this,"WeakSet"),t,!0)}},e,!1,!0)},function(t,n,r){"use strict";var e=r(1),i=r(173),o=r(17),u=r(8),c=r(21),f=r(138);e(e.P,"Array",{flatMap:function(t){var n,r,e=o(this);return c(t),n=u(e.length),r=f(e,0),i(r,e,e,n,0,1,t,arguments[1]),r}}),r(67)("flatMap")},function(t,n,r){"use strict";var e=r(1),i=r(173),o=r(17),u=r(8),c=r(49),f=r(138);e(e.P,"Array",{flatten:function(){var t=arguments[0],n=o(this),r=u(n.length),e=f(n,0);return i(e,n,n,r,0,void 0===t?1:c(t)),e}}),r(67)("flatten")},function(t,n,r){"use strict";var e=r(1),i=r(120)(!0);e(e.P,"Array",{includes:function(t){return i(this,t,1<arguments.length?arguments[1]:void 0)}}),r(67)("includes")},function(t,n,r){var e=r(1),i=r(150)(),o=r(3).process,u="process"==r(45)(o);e(e.G,{asap:function(t){var n=u&&o.domain;i(n?n.bind(t):t)}})},function(t,n,r){var e=r(1),i=r(45);e(e.S,"Error",{isError:function(t){return"Error"===i(t)}})},function(t,n,r){var e=r(1);e(e.G,{global:r(3)})},function(t,n,r){r(129)("Map")},function(t,n,r){r(130)("Map")},function(t,n,r){var e=r(1);e(e.P+e.R,"Map",{toJSON:r(171)("Map")})},function(t,n,r){var e=r(1);e(e.S,"Math",{clamp:function(t,n,r){return Math.min(r,Math.max(n,t))}})},function(t,n,r){var e=r(1);e(e.S,"Math",{DEG_PER_RAD:Math.PI/180})},function(t,n,r){var e=r(1),i=180/Math.PI;e(e.S,"Math",{degrees:function(t){return t*i}})},function(t,n,r){var e=r(1),o=r(181),u=r(179);e(e.S,"Math",{fscale:function(t,n,r,e,i){return u(o(t,n,r,e,i))}})},function(t,n,r){var e=r(1);e(e.S,"Math",{iaddh:function(t,n,r,e){var i=t>>>0,o=r>>>0;return(n>>>0)+(e>>>0)+((i&o|(i|o)&~(i+o>>>0))>>>31)|0}})},function(t,n,r){var e=r(1);e(e.S,"Math",{imulh:function(t,n){var r=+t,e=+n,i=65535&r,o=65535&e,u=r>>16,c=e>>16,f=(u*o>>>0)+(i*o>>>16);return u*c+(f>>16)+((i*c>>>0)+(65535&f)>>16)}})},function(t,n,r){var e=r(1);e(e.S,"Math",{isubh:function(t,n,r,e){var i=t>>>0,o=r>>>0;return(n>>>0)-(e>>>0)-((~i&o|~(i^o)&i-o>>>0)>>>31)|0}})},function(t,n,r){var e=r(1);e(e.S,"Math",{RAD_PER_DEG:180/Math.PI})},function(t,n,r){var e=r(1),i=Math.PI/180;e(e.S,"Math",{radians:function(t){return t*i}})},function(t,n,r){var e=r(1);e(e.S,"Math",{scale:r(181)})},function(t,n,r){var e=r(1);e(e.S,"Math",{signbit:function(t){return(t=+t)!=t?t:0==t?1/t==1/0:0<t}})},function(t,n,r){var e=r(1);e(e.S,"Math",{umulh:function(t,n){var r=+t,e=+n,i=65535&r,o=65535&e,u=r>>>16,c=e>>>16,f=(u*o>>>0)+(i*o>>>16);return u*c+(f>>>16)+((i*c>>>0)+(65535&f)>>>16)}})},function(t,n,r){"use strict";var e=r(1),i=r(17),o=r(21),u=r(11);r(10)&&e(e.P+r(126),"Object",{__defineGetter__:function(t,n){u.f(i(this),t,{get:o(n),enumerable:!0,configurable:!0})}})},function(t,n,r){"use strict";var e=r(1),i=r(17),o=r(21),u=r(11);r(10)&&e(e.P+r(126),"Object",{__defineSetter__:function(t,n){u.f(i(this),t,{set:o(n),enumerable:!0,configurable:!0})}})},function(t,n,r){var e=r(1),i=r(186)(!0);e(e.S,"Object",{entries:function(t){return i(t)}})},function(t,n,r){var e=r(1),f=r(187),a=r(33),s=r(31),l=r(139);e(e.S,"Object",{getOwnPropertyDescriptors:function(t){for(var n,r,e=a(t),i=s.f,o=f(e),u={},c=0;o.length>c;)void 0!==(r=i(e,n=o[c++]))&&l(u,n,r);return u}})},function(t,n,r){"use strict";var e=r(1),i=r(17),o=r(53),u=r(32),c=r(31).f;r(10)&&e(e.P+r(126),"Object",{__lookupGetter__:function(t){var n,r=i(this),e=o(t,!0);do{if(n=c(r,e))return n.get}while(r=u(r))}})},function(t,n,r){"use strict";var e=r(1),i=r(17),o=r(53),u=r(32),c=r(31).f;r(10)&&e(e.P+r(126),"Object",{__lookupSetter__:function(t){var n,r=i(this),e=o(t,!0);do{if(n=c(r,e))return n.set}while(r=u(r))}})},function(t,n,r){var e=r(1),i=r(186)(!1);e(e.S,"Object",{values:function(t){return i(t)}})},function(t,n,r){"use strict";var e=r(1),o=r(3),u=r(46),i=r(150)(),c=r(7)("observable"),f=r(21),a=r(2),s=r(70),l=r(76),h=r(26),v=r(71),p=v.RETURN,d=function(t){return null==t?void 0:f(t)},y=function(t){var n=t._c;n&&(t._c=void 0,n())},g=function(t){return void 0===t._o},b=function(t){g(t)||(t._o=void 0,y(t))},x=function(t,n){a(t),this._c=void 0,this._o=t,t=new m(this);try{var r=n(t),e=r;null!=r&&("function"==typeof r.unsubscribe?r=function(){e.unsubscribe()}:f(r),this._c=r)}catch(n){return void t.error(n)}g(this)&&y(this)};x.prototype=l({},{unsubscribe:function(){b(this)}});var m=function(t){this._s=t};m.prototype=l({},{next:function(t){var n=this._s;if(!g(n)){var r=n._o;try{var e=d(r.next);if(e)return e.call(r,t)}catch(t){try{b(n)}finally{throw t}}}},error:function(t){var n=this._s;if(g(n))throw t;var r=n._o;n._o=void 0;try{var e=d(r.error);if(!e)throw t;t=e.call(r,t)}catch(t){try{y(n)}finally{throw t}}return y(n),t},complete:function(t){var n=this._s;if(!g(n)){var r=n._o;n._o=void 0;try{var e=d(r.complete);t=e?e.call(r,t):void 0}catch(t){try{y(n)}finally{throw t}}return y(n),t}}});var S=function(t){s(this,S,"Observable","_f")._f=f(t)};l(S.prototype,{subscribe:function(t){return new x(t,this._f)},forEach:function(e){var i=this;return new(u.Promise||o.Promise)(function(t,n){f(e);var r=i.subscribe({next:function(t){try{return e(t)}catch(t){n(t),r.unsubscribe()}},error:n,complete:t})})}}),l(S,{from:function(t){var n="function"==typeof this?this:S,r=d(a(t)[c]);if(r){var e=a(r.call(t));return e.constructor===n?e:new n(function(t){return e.subscribe(t)})}return new n(function(n){var r=!1;return i(function(){if(!r){try{if(v(t,!1,function(t){if(n.next(t),r)return p})===p)return}catch(t){if(r)throw t;return void n.error(t)}n.complete()}}),function(){r=!0}})},of:function(){for(var t=0,n=arguments.length,e=new Array(n);t<n;)e[t]=arguments[t++];return new("function"==typeof this?this:S)(function(n){var r=!1;return i(function(){if(!r){for(var t=0;t<e.length;++t)if(n.next(e[t]),r)return;n.complete()}}),function(){r=!0}})}}),h(S.prototype,c,function(){return this}),e(e.G,{Observable:S}),r(77)("Observable")},function(t,n,r){"use strict";var e=r(1),i=r(46),o=r(3),u=r(119),c=r(191);e(e.P+e.R,"Promise",{finally:function(n){var r=u(this,i.Promise||o.Promise),t="function"==typeof n;return this.then(t?function(t){return c(r,n()).then(function(){return t})}:n,t?function(t){return c(r,n()).then(function(){throw t})}:n)}})},function(t,n,r){"use strict";var e=r(1),i=r(151),o=r(190);e(e.S,"Promise",{try:function(t){var n=i.f(this),r=o(t);return(r.e?n.reject:n.resolve)(r.v),n.promise}})},function(t,n,r){var e=r(56),i=r(2),o=e.key,u=e.set;e.exp({defineMetadata:function(t,n,r,e){u(t,n,i(r),o(e))}})},function(t,n,r){var e=r(56),o=r(2),u=e.key,c=e.map,f=e.store;e.exp({deleteMetadata:function(t,n){var r=arguments.length<3?void 0:u(arguments[2]),e=c(o(n),r,!1);if(void 0===e||!e.delete(t))return!1;if(e.size)return!0;var i=f.get(n);return i.delete(r),!!i.size||f.delete(n)}})},function(t,n,r){var o=r(199),u=r(167),e=r(56),i=r(2),c=r(32),f=e.keys,a=e.key,s=function(t,n){var r=f(t,n),e=c(t);if(null===e)return r;var i=s(e,n);return i.length?r.length?u(new o(r.concat(i))):i:r};e.exp({getMetadataKeys:function(t){return s(i(t),arguments.length<2?void 0:a(arguments[1]))}})},function(t,n,r){var e=r(56),i=r(2),o=r(32),u=e.has,c=e.get,f=e.key,a=function(t,n,r){if(u(t,n,r))return c(t,n,r);var e=o(n);return null!==e?a(t,e,r):void 0};e.exp({getMetadata:function(t,n){return a(t,i(n),arguments.length<3?void 0:f(arguments[2]))}})},function(t,n,r){var e=r(56),i=r(2),o=e.keys,u=e.key;e.exp({getOwnMetadataKeys:function(t){return o(i(t),arguments.length<2?void 0:u(arguments[1]))}})},function(t,n,r){var e=r(56),i=r(2),o=e.get,u=e.key;e.exp({getOwnMetadata:function(t,n){return o(t,i(n),arguments.length<3?void 0:u(arguments[2]))}})},function(t,n,r){var e=r(56),i=r(2),o=r(32),u=e.has,c=e.key,f=function(t,n,r){if(u(t,n,r))return!0;var e=o(n);return null!==e&&f(t,e,r)};e.exp({hasMetadata:function(t,n){return f(t,i(n),arguments.length<3?void 0:c(arguments[2]))}})},function(t,n,r){var e=r(56),i=r(2),o=e.has,u=e.key;e.exp({hasOwnMetadata:function(t,n){return o(t,i(n),arguments.length<3?void 0:u(arguments[2]))}})},function(t,n,r){var e=r(56),i=r(2),o=r(21),u=e.key,c=e.set;e.exp({metadata:function(r,e){return function(t,n){c(r,e,(void 0!==n?i:o)(t),u(n))}}})},function(t,n,r){r(129)("Set")},function(t,n,r){r(130)("Set")},function(t,n,r){var e=r(1);e(e.P+e.R,"Set",{toJSON:r(171)("Set")})},function(t,n,r){"use strict";var e=r(1),i=r(131)(!0);e(e.P,"String",{at:function(t){return i(this,t)}})},function(t,n,r){"use strict";var e=r(1),i=r(51),o=r(8),u=r(124),c=r(115),f=RegExp.prototype,a=function(t,n){this._r=t,this._s=n};r(146)(a,"RegExp String",function(){var t=this._r.exec(this._s);return{value:t,done:null===t}}),e(e.P,"String",{matchAll:function(t){if(i(this),!u(t))throw TypeError(t+" is not a regexp!");var n=String(this),r="flags"in f?String(t.flags):c.call(t),e=new RegExp(t.source,~r.indexOf("g")?r:"g"+r);return e.lastIndex=o(t.lastIndex),new a(e,n)}})},function(t,n,r){"use strict";var e=r(1),i=r(193),o=r(133),u=/Version\/10\.\d+(\.\d+)?( Mobile\/\w+)? Safari\//.test(o);e(e.P+e.F*u,"String",{padEnd:function(t){return i(this,t,1<arguments.length?arguments[1]:void 0,!1)}})},function(t,n,r){"use strict";var e=r(1),i=r(193),o=r(133),u=/Version\/10\.\d+(\.\d+)?( Mobile\/\w+)? Safari\//.test(o);e(e.P+e.F*u,"String",{padStart:function(t){return i(this,t,1<arguments.length?arguments[1]:void 0,!0)}})},function(t,n,r){"use strict";r(84)("trimLeft",function(t){return function(){return t(this,1)}},"trimStart")},function(t,n,r){"use strict";r(84)("trimRight",function(t){return function(){return t(this,2)}},"trimEnd")},function(t,n,r){r(160)("asyncIterator")},function(t,n,r){r(160)("observable")},function(t,n,r){var e=r(1);e(e.S,"System",{global:r(3)})},function(t,n,r){r(129)("WeakMap")},function(t,n,r){r(130)("WeakMap")},function(t,n,r){r(129)("WeakSet")},function(t,n,r){r(130)("WeakSet")},function(t,n,r){for(var e=r(162),i=r(74),o=r(27),u=r(3),c=r(26),f=r(82),a=r(7),s=a("iterator"),l=a("toStringTag"),h=f.Array,v={CSSRuleList:!0,CSSStyleDeclaration:!1,CSSValueList:!1,ClientRectList:!1,DOMRectList:!1,DOMStringList:!1,DOMTokenList:!0,DataTransferItemList:!1,FileList:!1,HTMLAllCollection:!1,HTMLCollection:!1,HTMLFormElement:!1,HTMLSelectElement:!1,MediaList:!0,MimeTypeArray:!1,NamedNodeMap:!1,NodeList:!0,PaintRequestList:!1,Plugin:!1,PluginArray:!1,SVGLengthList:!1,SVGNumberList:!1,SVGPathSegList:!1,SVGPointList:!1,SVGStringList:!1,SVGTransformList:!1,SourceBufferList:!1,StyleSheetList:!0,TextTrackCueList:!1,TextTrackList:!1,TouchList:!1},p=i(v),d=0;d<p.length;d++){var y,g=p[d],b=v[g],x=u[g],m=x&&x.prototype;if(m&&(m[s]||c(m,s,h),m[l]||c(m,l,g),f[g]=h,b))for(y in e)m[y]||o(m,y,e[y],!0)}},function(t,n,r){var e=r(1),i=r(158);e(e.G+e.B,{setImmediate:i.set,clearImmediate:i.clear})},function(t,n,r){var e=r(3),i=r(1),o=r(133),u=[].slice,c=/MSIE .\./.test(o),f=function(i){return function(t,n){var r=2<arguments.length,e=!!r&&u.call(arguments,2);return i(r?function(){("function"==typeof t?t:Function(t)).apply(this,e)}:t,n)}};i(i.G+i.B+i.F*c,{setTimeout:f(e.setTimeout),setInterval:f(e.setInterval)})},function(t,n,r){r(343),r(282),r(284),r(283),r(286),r(288),r(293),r(287),r(285),r(295),r(294),r(290),r(291),r(289),r(281),r(292),r(296),r(297),r(249),r(251),r(250),r(299),r(298),r(269),r(279),r(280),r(270),r(271),r(272),r(273),r(274),r(275),r(276),r(277),r(278),r(252),r(253),r(254),r(255),r(256),r(257),r(258),r(259),r(260),r(261),r(262),r(263),r(264),r(265),r(266),r(267),r(268),r(330),r(335),r(342),r(333),r(325),r(326),r(331),r(336),r(338),r(321),r(322),r(323),r(324),r(327),r(328),r(329),r(332),r(334),r(337),r(339),r(340),r(341),r(244),r(246),r(245),r(248),r(247),r(233),r(231),r(237),r(234),r(240),r(242),r(230),r(236),r(227),r(241),r(225),r(239),r(238),r(232),r(235),r(224),r(226),r(229),r(228),r(243),r(162),r(315),r(197),r(320),r(198),r(316),r(317),r(318),r(319),r(300),r(196),r(199),r(200),r(355),r(344),r(345),r(350),r(353),r(354),r(348),r(351),r(349),r(352),r(346),r(347),r(301),r(302),r(303),r(304),r(305),r(308),r(306),r(307),r(309),r(310),r(311),r(312),r(314),r(313),r(358),r(356),r(357),r(399),r(402),r(401),r(403),r(404),r(400),r(405),r(406),r(380),r(383),r(379),r(377),r(378),r(381),r(382),r(364),r(398),r(363),r(397),r(409),r(411),r(362),r(396),r(408),r(410),r(361),r(407),r(360),r(365),r(366),r(367),r(368),r(369),r(371),r(370),r(372),r(373),r(374),r(376),r(375),r(385),r(386),r(387),r(388),r(390),r(389),r(392),r(391),r(393),r(394),r(395),r(359),r(384),r(414),r(413),r(412),t.exports=r(46)},function(t,n){t.exports=function(t,n){if("string"==typeof n)return t.insertAdjacentHTML("afterend",n);var r=t.nextSibling;return r?t.parentNode.insertBefore(n,r):t.parentNode.appendChild(n)}}])</script><script src="/./main.ee3baa.js"></script><script>!function(){var e,t;e="/slider.aea4fb.js",t=document.createElement("script"),document.getElementsByTagName("body")[0].appendChild(t),t.setAttribute("src",e)}()</script>


    
<div class="tools-col" q-class="show:isShow,hide:isShow|isFalse" q-on="click:stop(e)">
  <div class="tools-nav header-menu">
    
    
      
      
      
    
      
      
      
    
      
      
      
    
    

    <ul style="width: 70%">
    
    
      
      <li style="width: 33.333333333333336%" q-on="click: openSlider(e, 'innerArchive')"><a href="javascript:void(0)" q-class="active:innerArchive">文章搜索</a></li>
      
        
      
      <li style="width: 33.333333333333336%" q-on="click: openSlider(e, 'friends')"><a href="javascript:void(0)" q-class="active:friends">友情链接</a></li>
      
        
      
      <li style="width: 33.333333333333336%" q-on="click: openSlider(e, 'aboutme')"><a href="javascript:void(0)" q-class="active:aboutme">关于我</a></li>
      
        
    </ul>
  </div>
  <div class="tools-wrap">
    
    	<section class="tools-section tools-section-all" q-show="innerArchive">
        <div class="search-wrap">
          <input class="search-ipt" q-model="search" type="text" placeholder="find something…">
          <i class="icon-search icon" q-show="search|isEmptyStr"></i>
          <i class="icon-close icon" q-show="search|isNotEmptyStr" q-on="click:clearChose(e)"></i>
        </div>
        <div class="widget tagcloud search-tag">
          <p class="search-tag-wording">tag:</p>
          <label class="search-switch">
            <input type="checkbox" q-on="click:toggleTag(e)" q-attr="checked:showTags">
          </label>
          <ul class="article-tag-list" q-show="showTags">
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color2">Docker</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color1">Dubbo</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color2">ECMAScript6</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color1">JavaScript</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color4">Git</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color3">ElasticStack</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color5">Hibernate</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color4">ORM</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color1">Linux</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color2">Lucene</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color1">Maven</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color3">NoSQL存储</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color3">MongoDB</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color3">MyBatis</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color1">MySQL</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color3">Mybatis-Plus</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color1">Nginx</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color3">Node.js</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color2">artTemplate</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color3">Express</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color4">NPM</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color1">Redis</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color2">Spring</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color3">Struts2</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color1">SpringBoot</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color2">SpringCloud</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color1">SpringData</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color5">SpringMVC</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color4">Vue</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color5">less</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color5">预处理器</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color5">Hexo</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color2">GitHub</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color5">zookeeper</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color5">网络爬虫</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color4">RabbitMQ</a>
              </li>
             
              <li class="article-tag-list-item">
                <a href="javascript:void(0)" class="js-tag color4">Elasticsearch</a>
              </li>
            
            <div class="clearfix"></div>
          </ul>
        </div>
        <ul class="search-ul">
          <p q-show="jsonFail" style="padding: 20px; font-size: 12px;">
            缺失模块。<br/>1、请确保node版本大于6.2<br/>2、在博客根目录（注意不是yilia根目录）执行以下命令：<br/> npm i hexo-generator-json-content --save<br/><br/>
            3、在根目录_config.yml里添加配置：
<pre style="font-size: 12px;" q-show="jsonFail">
  jsonContent:
    meta: false
    pages: false
    posts:
      title: true
      date: true
      path: true
      text: false
      raw: false
      content: false
      slug: false
      updated: false
      comments: false
      link: false
      permalink: false
      excerpt: false
      categories: false
      tags: true
</pre>
          </p>
          <li class="search-li" q-repeat="items" q-show="isShow">
            <a q-attr="href:path|urlformat" class="search-title"><i class="icon-quo-left icon"></i><span q-text="title"></span></a>
            <p class="search-time">
              <i class="icon-calendar icon"></i>
              <span q-text="date|dateformat"></span>
            </p>
            <p class="search-tag">
              <i class="icon-price-tags icon"></i>
              <span q-repeat="tags" q-on="click:choseTag(e, name)" q-text="name|tagformat"></span>
            </p>
          </li>
        </ul>
    	</section>
    

    
    	<section class="tools-section tools-section-friends" q-show="friends">
  		
        <ul class="search-ul">
          
            <li class="search-li">
              <a href="https://gitee.com/wgy1993" target="_blank" class="search-title"><i class="icon-quo-left icon"></i>我的码云</a>
            </li>
          
            <li class="search-li">
              <a href="https://wgy1993.gitee.io" target="_blank" class="search-title"><i class="icon-quo-left icon"></i>GiteePages服务</a>
            </li>
          
            <li class="search-li">
              <a href="https://github.com/wgy1993" target="_blank" class="search-title"><i class="icon-quo-left icon"></i>我的git</a>
            </li>
          
            <li class="search-li">
              <a href="https://wgy1993.github.io" target="_blank" class="search-title"><i class="icon-quo-left icon"></i>GitPages服务</a>
            </li>
          
        </ul>
  		
    	</section>
    

    
    	<section class="tools-section tools-section-me" q-show="aboutme">
  	  	
  	  		<div class="aboutme-wrap" id="js-aboutme">程序员的一天</div>
  	  	
    	</section>
    
  </div>
  
</div>
    <!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                      <div class="pswp__preloader__cut">
                        <div class="pswp__preloader__donut"></div>
                      </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div> 
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>
  </div>
</body>
</html>